国产探花免费观看_亚洲丰满少妇自慰呻吟_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})
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 民和| 遂昌县| 盖州市| 裕民县| 塔城市| 丹寨县| 东兴市| 鹰潭市| 宁明县| 仙游县| 马山县| 天水市| 宝鸡市| 灌南县| 汉寿县| 南江县| 达孜县| 西和县| 石屏县| 囊谦县| 韶关市| 虎林市| 绥阳县| 长岭县| 大理市| 福海县| 黔西| 图片| 鹤庆县| 新余市| 开江县| 苗栗县| 都匀市| 郎溪县| 通辽市| 邯郸县| 讷河市| 景洪市| 治多县| 贡嘎县| 白朗县|