Conversion Transforms
class torchvision.transforms.ToTensor
把一个取值范围是[0,255]的PIL.Image或者shape为(H,W,C)的numpy.ndarray,转换成形状为[C,H,W],取值范围是[0,1.0]的torch.FloadTensor
data = np.random.randint(0, 255, size=300)img = data.reshape(10,10,3)print(img.shape)img_tensor = transforms.ToTensor()(img) # 转换成tensorprint(img_tensor)
class torchvision.transforms.ToPILImage
将shape为(C,H,W)的Tensor或shape为(H,W,C)的numpy.ndarray转换成PIL.Image,值不变。