torch 笔记

torchvision

transforms

from torchvision import transforms

transform = transforms.Compose([
        transforms.ToTensor(),
    transforms.Normalize(mean = (0.5, 0.5, 0.5), std = (0.5, 0.5, 0.5)),
])

ToTensor()PIL.Imagenumpy.ndarray 数据进转化为 torch.FloadTensor,并归一化到[0, 1.0]

  • 形状为 [H, W, C]numpy.ndarray,转换成形状为 [C, H, W],取值范围是 [0, 1.0]torch.FloadTensor
  • 取值范围为 [0, 255]PIL.Image,转换成形状为 [C, H, W],取值范围是 [0, 1.0]torch.FloadTensor

你可能感兴趣的:(torch 笔记)