ToTensor¶
- class torchvision.transforms.ToTensor[source]¶
将 PIL 图像或 ndarray 转换为 tensor 并相应地缩放值。
此转换不支持 torchscript。
如果 PIL 图像属于模式 (L, LA, P, I, F, RGB, YCbCr, RGBA, CMYK, 1) 之一,或者 numpy.ndarray 的 dtype = np.uint8,则将范围 [0, 255] 中的 PIL 图像或 numpy.ndarray (H x W x C) 转换为范围 [0.0, 1.0] 中的形状为 (C x H x W) 的 torch.FloatTensor
在其他情况下,将返回未缩放的 tensor。
注意
由于输入图像被缩放到 [0.0, 1.0],因此在转换目标图像掩码时不应使用此转换。有关实现图像掩码转换的信息,请参阅references。