Reputation:
i have a piece of code
la=[0,0,0,0,0,0,1,1,1,1]
onehot = tf.one_hot(la, depth=2) #[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[0,1],[0,1],[0,1],[0,1]]
image_batch,labels_batch=tf.train.batch([resized_image,onehot],batch_size=2,num_threads=1)
when i run
print(s.run([tf.shape(image_batch),labels_batch]))
it is batching all labes at a time,like
[array([ 2, 50, 50, 3]), array([[[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 0., 1.],
[ 0., 1.],
[ 0., 1.],
[ 0., 1.]],
[[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 1., 0.],
[ 0., 1.],
[ 0., 1.],
[ 0., 1.],
[ 0., 1.]]], dtype=float32)]
it should output something like
[array([ 2, 50, 50, 3]), array([[[ 1., 0.],
[[ 1., 0.]]], dtype=float32)]
doesn't it? as batch size is 2 and taking 2 images and it's corresponding labels at a time. i'm new to CNN and machine learning.thanks beforehand.
Upvotes: 0
Views: 387
Reputation: 1829
According to the Tensorflow documentation of tf.train.batch (https://www.tensorflow.org/api_docs/python/tf/train/batch),
Since the enqueue_many=False by default and your input onehot have the shape of [10, 2], then the output (here labels_batch) shape become [batch_size, 10, 2].
if the enqueue_many=True, then only the output (here labels_batch) will become [batch_size,2].
Hope this helps.
Upvotes: 1