How to view a tensor as an image?

Hi, I was working on a project where I have a tensor output. How do I view it is an image?

What I’ve tried so far:

arr_ = np.squeeze(out_p)

The error:

RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.

I tried some of the answers mentioned on this forum and on stackoverflow, all to vain.
If anyone help, I would be very grateful

Did you try to add the suggested tensor.detach().numpy() operation from the error message?
If so, what was the new error?

1 Like

I was wondering if I am doing it wrong?
This is what I’ve done so far:

arr_ = np.squeeze(out_img2)

The error is: TypeError: Invalid shape (3, 512, 512) for image data

And when I tried:

arr_ = out_img2.squeeze

The error is: TypeError: Image data of dtype object cannot be converted to float

Edit: Solved it.I had forgotten to permute!