0
点赞
收藏
分享

微信扫一扫

numpy和torch读彩色图像区别

小a草 2022-04-13 阅读 75

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])
举报

相关推荐

0 条评论