图片数据处理

from PIL import Image 
import numpy as np
from torchvision import transforms

#读取图片
img = Image.open('data/hymenoptera_data/train/bees/3030772428_8578335616.jpg')  

#PIL图片转换为ndarray
img_array = np.array(img)  

#PIL图片转换为tensor
trans = torchvision.transforms.ToTensor()
img_tensor = trans(img)

#tensor转换为PIL
toPIL = torchvision.transforms.ToPILImage()
img_ = toPIL(img_tensor)
上一篇:C/C++混合调用(链接指示)


下一篇:2020-12-24