图片数据处理
作者:互联网
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)
标签:PIL,tensor,img,torchvision,transforms,数据处理,import,图片 来源: https://www.cnblogs.com/bill-h/p/15859781.html