I learned some data with tensorflow.
For the test, I saw the shape of the final result.
It was tensor of (1, 80, 80, 1).
I use matplotlib or PIL to do this,
I wanted to see the image after changing to a pie array.
But I could not change the tensor to numpy.
I could not do anything because of the session even if I used eval ().
There is no way to convert tensor to numpy.
Can I see the tensor as an image?
(mytensor1) # mytensor
arr = np.ndarray(mytensor1)
arr_ = np.squeeze(arr)
plt.imshow(arr_)
plt.show()
but there is error message: TypeError: expected sequence object with len >= 0 or a single integer
You can use squeeze function from numpy. For example
arr = np.ndarray((1,80,80,1))#This is your tensor
arr_ = np.squeeze(arr) # you can give axis attribute if you wanna squeeze in specific dimension
plt.imshow(arr_)
plt.show()
Now, you can easily display this image (e.g. above code, assuming you are using matplotlib.pyplot as plt
).
For people using PyTorch, the simplest way that I know is this:
import matplotlib.pyplot as plt
plt.imshow(my_tensor.numpy()[0], cmap='gray')
That should do it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With