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)


but the shape is coming as unknown:

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

Any idea what I am doing wrong?

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

1 Answer 1


For tensorflow 1.x we need to execute


to see results before creating a tf session.

For tf 2.x eager execution is enabled by default.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.