0
$\begingroup$

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?

$\endgroup$
  • 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 '19 at 9:57
  • $\begingroup$ well I added the statement, but missed to execute it :D Thanks @hssay $\endgroup$ – Mrinal Aug 7 '19 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 '19 at 15:47
0
$\begingroup$

For tensorflow 1.x we need to execute

tf.enable_eager_execution() 

to see results before creating a tf session.

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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