I am following this example to read an image (from my disk) with tensorflow:

img_raw = tf.io.read_file(image_path)
img_tensor = tf.image.decode_image(img_raw)

print(repr(img_raw))
print(img_tensor.shape)
print(img_tensor.dtype)


but the shape is coming as unknown:

<tf.Tensor 'ReadFile_4:0' shape=() dtype=string>
<unknown>
<dtype: 'uint8'>


Any idea what I am doing wrong?

• Have you enabled eager execution? It could be the case that TF isn't reading the image since eager execution is not enabled. Aug 7 '19 at 9:57
• well I added the statement, but missed to execute it :D Thanks @hssay Aug 7 '19 at 13:46
• Great! Can you add an answer yourself and close it? It can help others with similar questions in the future. Aug 9 '19 at 15:47

tf.enable_eager_execution()