I run the code below, it raises an ValueError: \'images\' contains no shape
. Therefore I have to add the line behind #
to set the static shape, but
The issue here actually comes from the fact that tf.image.decode_image
doesn't return the shape of the image. This was explained in these two GitHub issues: issue1, issue2.
The problem comes from the fact that tf.image.decode_image
also handles .gif
, which returns a 4D tensor, whereas .jpg
and .png
return 3D images. Therefore, the correct shape cannot be returned.
The solution is to simply use tf.image.decode_jpeg
or tf.image.decode_png
(both work the same and can be used on .png
and .jpg
images).
def _decode_image(filename):
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string, channels=3)
image = tf.cast(image_decoded, tf.float32)
image_resized = tf.image.resize_images(image, [224, 224])
return image_resized