0

I am trying to convert tensor of an image which is of shape(253,223) to numpy array of the same size so that I can plot the image. I have looked at the documentation and they suggested me to use the eval function as

sess = tf.Session()
with sess.as_default():
   print(type(tf.constant([img1]).eval()))

but it throws the error "List of Tensors when single Tensor expected".

Here type(img1) is <class 'tensorflow.python.framework.ops.Tensor'> and shape is (253, 223) . Using keras

tf.keras.backend.eval(x)

it throws

InvalidArgumentError: Input to DecodeRaw has length 56419 that is not a multiple of 4, the size of float [[{{node DecodeRaw}}]] error.

How can I convert given tensor to numpy array of the same dimension?

Shivam Sahu
  • 195
  • 1
  • 1
  • 12

1 Answers1

1

Any tensor returned by Session.run or eval is a NumPy array.

>>> print(type(tf.Session().run(tf.constant([1,2,3]))))

Or:

>>> sess = tf.InteractiveSession()
    print(type(tf.constant([1,2,3]).eval()))
    <class 'numpy.ndarray'>
Azer Gorai
  • 37
  • 1
  • 8
  • Yeah, It works fine but the same thing with above doesn't work. It is throwing an error "List of Tensors when single Tensor expected". – Shivam Sahu May 28 '19 at 13:54