处理图片的库
- PIL的图片:
WH(Weight×Height)格式
HWC(Height×Weight×Channel)格式,其中Channel为RGB格式,图片默认类型为uint8 - opencv的图片:
HWC(Height×Weight×Channel)格式,其中Channel为BGR格式,图片默认类型为uint8 - pytorch(tensor)的图片:
CHW格式(Channel×Height×Weight)格式,其中Channel为RGB格式,图片默认类型为uint8 - tensorflow的图片:
HWC(Height×Weight×Channel)格式,其中Channel为RGB格式,图片默认类型为uint8
PIL转换为Tensor
from torchvision import transformstransform = transforms.Compose([transforms.ToTensor()])
image_PIL = transform(image_tensor)# 或者
image_PIL = transforms.ToTensor()(image_tensor)
Tensor转换为PIL
from torchvision import transformsimage_tensor = transforms.ToPILImage()(image_tensor)
参考
深度学习常用格式及注意
torchvision库学习之transforms.ToPILImage(函数)