tensorflow: Result of tf.reshape() with dynamic shape does not work with tf.train.shuffle_batch()
I wrote the images into TensorFlow format file, but when I read it like this:
features = tf.parse_single_example(
serialized_example,
features = {
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64),
'channel': tf.FixedLenFeature([], tf.int64),
'image': tf.FixedLenFeature([], tf.string),
'gt': tf.FixedLenFeature([], tf.string),
})
first, the data has no shape infomation, only the batch size, so I reshape it, but parameter shape of tf.reshape() only support list of integers, not a tensor, I don’t know why?
second, the data of gt is list, maybe length(gt) > 2, because no shape information, so I can’t unpack it
so, why is not shape information available
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (6 by maintainers)
Ah, so the
tf.reshape()works as intended, but you then use the result in a call totf.train.shuffle_batch()and that fails? I’m afraid that this is expected behavior.As the docs for
tf.train.shuffle_batch()say, you must either have fully-defined (i.e. static) shapes for all of the tensors you pass in thetensor_listargument (or you must specify explicit shapes for them). For TensorFlow to batch your images (or other tensors) together, they must all have the same shape. You cannot pass the result of a dynamictf.reshape(), because each element might have a different shape, and TensorFlow cannot batch them.Your best option is to resize, crop, or pad the input images to a static shape before passing them to
tf.train.shuffle_batch(). For example, the Inception input pipeline usestf.image.resize_images()to resize images to a standard size, so that they can be batched (usingtf.train.batch_join()in this case).If you know that
imagehas a static shape[h, w, c], whereh,w, andcare Pythonintvalues, you can simply call:…and you don’t need the
tf.reshape()because it should be a no-op. Then your code will work withtf.train.shuffle_batch().Look here @wangchuan http://stackoverflow.com/questions/35620157/how-can-i-use-values-read-from-tfrecords-as-arguments-to-tf-reshape @mrry already answered this question.