ToPILImage¶
- class torchvision.transforms.ToPILImage(mode=None)[source]¶
将张量或 ndarray 转换为 PIL 图像
此转换不支持 torchscript。
根据
mode调整值范围,将形状为 C x H x W 的 torch.*Tensor 或形状为 H x W x C 的 numpy ndarray 转换为 PIL 图像。- 参数:
mode (PIL.Image 模式) –
输入数据的色彩空间和像素深度(可选)。如果
mode为None(默认),则会对输入数据做出一些假设如果输入有 4 个通道,则
mode假定为RGBA。如果输入有 3 个通道,则
mode假定为RGB。如果输入有 2 个通道,则
mode假定为LA。如果输入有 1 个通道,则
mode由数据类型确定(即int、float、short)。