国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

tensorflow reading data (1)

2019-11-08 03:26:35
字體:
來源:轉載
供稿:網友

There are three main methods of getting data into a TensorFlow PRogram:

Feeding: Python code provides the data when running each step.Reading from files: an input pipeline reads the data from files at the beginning of a TensorFlow graph.Preloaded data: a constant or variable in the TensorFlow graph holds all the data (for small data sets).

Feeding

TensorFlow's feed mechanism lets you inject data into any Tensor in acomputation graph. A python computation can thus feed data directly into thegraph.

Supply feed data through the feed_dict argument to a run() or eval() callthat initiates computation.

with tf.session():  input = tf.placeholder(tf.float32)  classifier = ...  print(classifier.eval(feed_dict={input: my_python_preprocessing_fn()}))

While you can replace any Tensor with feed data, including variables andconstants, the best practice is to use aplaceholder op node. Aplaceholder exists solely to serve as the target of feeds. It is notinitialized and contains no data. A placeholder generates an error ifit is executed without a feed, so you won't forget to feed it.

An example using placeholder and feeding to train on MNIST data can be foundintensorflow/examples/tutorials/mnist/fully_connected_feed.py,and is described in the MNIST tutorial.

x = tf.placeholder(tf.float32, shape=(1024, 1024))y = tf.matmul(x, x)with tf.Session() as sess:  print(sess.run(y))  # ERROR: will fail because x was not fed.  rand_array = np.random.rand(1024, 1024)  print(sess.run(y, feed_dict={x: rand_array}))  # Will succeed.

tf.placeholder(dtype, shape=None, name=None)

Args:
dtype: The type of elements in the tensor to be fed.shape: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape.name: A name for the Operation (optional).
Returns:

A Tensor that may be used as a handle for feeding a value, but not evaluated directly.

                 for step in xrange(num_batch):                    batch_imgs, batch_labels = self.nextBatch(train_imgs, train_labels, step, BATCH_SIZE)                    # Fit training using batch data                    # print("IMG_PL = ", self.img_pl.get_shape())                    _, single_cost = sess.run([optimizer, cost], feed_dict={self.img_pl: batch_imgs, self.label_pl: batch_labels, self.keep_prob: dropout})
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南昌市| 讷河市| 林西县| 高清| 安康市| 南安市| 民权县| 平果县| 晋宁县| 满城县| 鄯善县| 米林县| 道孚县| 惠东县| 霍林郭勒市| 岳西县| 湄潭县| 德安县| 西藏| 五原县| 曲松县| 邯郸市| 巴东县| 科技| 舟山市| 石首市| 乌兰浩特市| 德格县| 施秉县| 谢通门县| 开阳县| 嘉祥县| 息烽县| 寿阳县| 青神县| 武邑县| 日照市| 黄浦区| 尼木县| 时尚| 阳新县|