Tensorflow: convert tensor to numpy array without .eval () or sess.run ()

How can you convert a tensor to Numpy ndarray without using eval or sess.run ()?

I need to pass the tensor to the feed dictionary, and I already have a session.

+4
source share
1 answer

The fact that you say that you already have a session implies a lack of understanding of what sess.run () does.

If tf.Session () is triggered, you can use it to retrieve any tensor using sess.run (). If you need to get a variable or constant tensor, this is very straightforward.

value = sess.run(tensor_to_retrieve)

If the tensor is the result of operations on placeholder tensors, you will need to pass them using feed_dict.

value = sess.run(tensor, feed_dict={input_placeholder: input_value})

, sess.run() .

+3

Source: https://habr.com/ru/post/1649469/


All Articles