Save Pytorch 4D tensor as image

In PyTorch this snippet is working and saving the image:

from torchvision.utils import save_image
import torch
import torchvision

tensor= torch.rand(2, 3, 400, 711) 

img1 = tensor[0]
save_image(img1, 'img1.png')

Before saving the image can you check the shape of the img1 in any case something happened.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top