数据使用方角度
首先从pytorch出发,torchvision.transforms()要求传入的图像是PIL.Image格式(通道要求是RGB格式的),另外模型处理输入要转换为[1,channel,H,W];
所以最终导入torchvision.transforms()的图像格式需要转成PIL.Image,且需要在转换后增加batch维度([channel,H,W]变成[1,channel,H,W])
test_transform=torchvision.transforms.Compose([
...
transforms.ToTensor(),
...
])
input_img=test_transform(img_pil).unsqueeze(0)
pred_logits=model(input_img)
OpenCV和PIL.Image区别
1. PIL.Image
a. 读取图片
from PIL import Image
img_pil = Image