ValueError: all forms must be fully defined. Problem due to commenting on tf.random_crop

This question expands somewhat. How can I use values ​​read from TFRecords as arguments to tf.reshape?

I transferred my images to a specific form with the following code:

height = tf.cast(features['height'],tf.int32) width = tf.cast(features['width'],tf.int32) image = tf.reshape(image,tf.pack([height, width, 3])) 

In cifar10_input code, the image is then distorted as follows: IMAGE_SIZE = 32:

 height = IMAGE_SIZE width = IMAGE_SIZE distorted_image = tf.random_crop(image, [height, width, 3]) 

However, for my purposes, I now do not need to make a random crop. Thus, I replaced this line as follows:

 distorted_image = image 

When I do this, it throws the following error:

 Traceback (most recent call last): File "cnn_train.py", line 128, in <module> tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/default/_app.py", line 30, in run sys.exit(main(sys.argv)) File "cnn_train.py", line 124, in main train() File "cnn_train.py", line 56, in train images, labels = cnn.distorted_inputs() File "/home/samuelchin/tensorflow/my_code/CNN/cnn.py", line 123, in distorted_inputs batch_size=BATCH_SIZE) File "/home/samuelchin/tensorflow/my_code/CNN/cnn_input.py", line 128, in distorted_inputs min_queue_examples, batch_size) File "/home/samuelchin/tensorflow/my_code/CNN/cnn_input.py", line 70, in _generate_image_and_label_batch min_after_dequeue=min_queue_examples) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/input.py", line 494, in shuffle_batch dtypes=types, shapes=shapes) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 404, in __init__ shapes = _as_shape_list(shapes, dtypes) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 70, in _as_shape_list raise ValueError("All shapes must be fully defined: %s" % shapes) ValueError: All shapes must be fully defined: [TensorShape([Dimension(None), Dimension(None), Dimension(None)]), TensorShape([])] 

I have 2 questions:

  • Why does this cause an error when I do not do tf.random_crop? It seems to me that tf.random_crop returns something that is completely different from the image.
  • Just sets IMAGE_SIZE to the size I want for a good solution? For example, if the images are 32 x 32, and I want to crop them to 24 x 24, I set IMAGE_SIZE = 24. Now, since I want it to be 32 x 32, should I just set IMAGE_SIZE = 32?
+4
tensorflow
source share
1 answer

Since you generate your image dynamically, including pulling the height and width dynamically from the tf recording file, TensorFlow does not know the shape of the resulting image. Many of the later pipeline operations should be able to define the form while Python is running.

tf.random_crop has a side effect from setting the image size to a known fixed size and leaving its shape for further processing.

You can simply slice the image to the required size instead of doing random_crop, but you need to do some operation to turn the image into a fixed-size object. If you want it to be 32x32, and you know that the input height and width is 32x32, then you can just do set_shape (but you will be better off). Otherwise, you can crop and / or resize to the desired size.

+6
source share

All Articles