Confused on how tensorflow feed

Recently started using tensorflow and I'm really confused on the functionality of feed_dict.

Looking at the mnist example from the tensorflow website, x is a symbolic placeholder that will be filled with a new batch of images every training iteration, so 'None' here could also be 'batch_size'

x = tf.placeholder(tf.float32, shape=[None, 784])

when looking at the convolutional part of this tutorial, there's a command to reshape x from it's flattened 1x784 shape back to a 2D image 28x28 shape

x_image = tf.reshape(x, [-1,28,28,1])

during the training loop, x is fed through the command

train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})

My question is when we feed in values to x, does tensorflow automatically vectorize every op involving x? So for example when we define the op

h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)

this will automatically work across the entire batch?

if x is ndarray with each row being a flattened image, because we specified shape 'None' in the x placeholder tensorflow automatically knows to use each row as an individual training sample, and vectorize all subsequent ops?


The shape argument is used for static shape inference (ie, tensor.get_shape ) and is optional. TensorFlow doesn't vectorize anything automatically, but for binary cwise ops it uses broadcasting which looks a bit like that. In your example, tf.conv2d is an operation that treats each row as an example, so it works with batches, but not with individual examples. Also batch[0] is a batch of inputs, and batch[1] is a batch of labels.

链接地址: http://www.djcxy.com/p/32106.html

上一篇: Tensorflow:值赋值操作的优先级

下一篇: 困惑于张量流如何进食