pytorch transform常用格式
from torchvision import transforms
tensor = transforms.Tensor() #初始化对象
#img_or_np为“PIL Image”或者"numpy.",即你要转化的对象
data = tensor(img_or_np)
trans_resize = transforms.Resize(512,512)
data = trans_resize(data)
#下面将数据data归一化,计算方法为:image=(image-mean)/std
'''
其中mean和std分别通过(0.5,0.5,0.5)和(0.5,0.5,0.5)进行指定。
原来的0-1最小值0则变成(0-0.5)/0.5=-1,而最大值1则变成(1-0.5)/0.5=1.
'''
trans_norm = transforms.Normalize([0.5,0.5,0.5],[0.5,0.5,0.5])
img_normal = trans_norm(data)