tensorflow: decode_image resize_images workflow does not work
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
- TensorFlow installed from (source or binary): Binary
- TensorFlow version (use command below): (‘v1.3.0-rc2-20-g0787eee’, ‘1.3.0’)
- Python version: 2.7
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:
- Exact command to reproduce: Performing
resize_imageswith output ofdecode_image
Describe the problem
This problem was addressed in https://github.com/tensorflow/tensorflow/issues/1029 but was closed. https://github.com/tensorflow/tensorflow/issues/8551 and https://github.com/tensorflow/tensorflow/issues/9356 are also relevant.
The basic problem is that the output of tf.image.decode_image cannot be passed to tf.image.resize_images. It raises ValueError: 'images' contains no shape. in the call to resize_images.
Possible workarounds to this include using decode_jpeg, decode_png or adding decoded_image.set_shape([None, None, None]) before calling tf.image.resize_images. However, as @girving pointed out in #1029, nothing about the underlying op requires knowing a static shape.
Source code / logs
decoded_image = tf.image.decode_jpeg(tf.read_file(image_filename))
tf.image.resize_images(decoded_image, (100, 100))
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 17 (9 by maintainers)
can’t believe this issue is still not addressed after 2 years. I had this problem in 1.13.1 (most recent version, except for tf 2.0beta)
But shouldn’t this stay open then? I mean, if we agree that there is a change needed, the change should be done some day eventually. When the ticket is closed, nobody will remember it and thus it will never be changed.
tf.image.decode_imageis a wrapper of many other ops:decode_jpeg,decode_gif,decode_png, etc, so the output shape depends on the image type, and it cannot determine the shape of the output until actually seeing the content at execution time.For now, you can simply replace the
tf.image.decode_imagewith more specific ops, i.e.,tf.image.decode_jpegfor jpeg,tf.image.decode_pngfor png, etc. (See https://www.tensorflow.org/api_docs/python/tf/image for more details).I try to run the offical sample code(https://www.tensorflow.org/programmers_guide/datasets) and get same error.
error detail: ----> 4 image_resized = tf.image.resize_images(image_decoded, [28, 28]) 5 return image_resized, label
–> 741 raise ValueError(‘'images' contains no shape.’) 742 # TODO(shlens): Migrate this functionality to the underlying Op’s. 743 is_batch = True
my tf versiom: tensorflow-gpu (1.4.1)
my python version: python 2.7
I worked with these decode image ops recently with the C++ API and I remember having to code a bunch of logic into the graph to guarantee a certain shape output.
@mingxingtan would it be possible to add a parameter to
tf.image.decode_imageto make this simpler? Maybe it could beforce=Nonefor existing behavior,force='4d'to add a JPEG/PNG/BMP have a fourth dimension, orforce='3d'to truncate GIF output to only have the first frame.Refer to Geoffrey Irving’s answer in https://github.com/tensorflow/tensorflow/issues/9356#issuecomment-309144064
Similar solution has been suggested by Nagashayan in https://stackoverflow.com/questions/44942729/tensorflowvalueerror-images-contains-no-shape