mathetes mathetes - 1 month ago 36
Python Question

How can I convert a tensor into a numpy array in TensorFlow?

I know how to convert a numpy array into a tensor object with the function

tf.convert_to_tensor(img.eval())
.

My problem is that after I apply some preprocessing to this tensors in terms of brightness, contrast, etc, I would like to view the resulting transformations to evaluate and tweak my parameters.

How can I convert a tensor into a numpy array so I can show it as an image with PIL?

Answer

To convert back from tensor to numpy array you can simply run .eval() on the transformed tensor.

Comments