numpy是channel放在最后,torch是放在前面(channel first)
举个例子:
import numpy as np
from PIL import Image
import torchvision
#一张彩色图像的路径
path3='/content/drive/MyDrive/Unet/dataset/testing/00001.png'
#Image读后转为numpy格式
print(np.array((Image.open(path3))).shape)
#转为torch
img_or = Image.open(path3)
img = torchvision.transforms.ToTensor()(img_or)
print(img.shape)
output:
(800, 600, 3)
torch.Size([3, 800, 600])