查看文档https://pytorch.org/docs/stable/torchvision/transforms.html的源码
[docs]class ToTensor(object): """Convert a ``PIL Image`` or ``numpy.ndarray`` to tensor. Converts a PIL Image or numpy.ndarray (H x W x C) in the range [0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0] if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr, RGBA, CMYK, 1) or if the numpy.ndarray has dtype = np.uint8 In the other cases, tensors are returned without scaling. """
本文深入解析PyTorch中ToTensor()函数的使用方法与原理,该函数能够将PIL Image或numpy.ndarray转换为torch.FloatTensor,并调整其形状和数值范围,适用于多种图像模式,如RGB、灰度等。
3628

被折叠的 条评论
为什么被折叠?



