decode_png¶
- torchvision.io.decode_png(input: Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGED, apply_exif_orientation: bool = False) Tensor [源代码]¶
将 PNG 图像解码为 3 维的 RGB 或灰度张量。
大多数情况下,输出张量的值为 uint8,范围为 [0, 255]。如果图像是 16 位 PNG,则输出张量为 uint16,范围为 [0, 65535](从 torchvision
0.21
开始支持)。由于 PyTorch 对 uint16 的支持有限,我们建议在此函数后调用torchvision.transforms.v2.functional.to_dtype()
并设置scale=True
,以便将解码后的图像转换为 uint8 或 float 张量。- 参数:
input (Tensor[1]) – 包含 PNG 图像原始字节的一维 uint8 张量。
mode (str 或 ImageReadMode) – 要将图像转换为的模式,例如“RGB”。默认为“UNCHANGED”。有关可用模式,请参阅
ImageReadMode
。apply_exif_orientation (bool) – 对输出张量应用 EXIF 方向变换。默认为 False。
- 返回:
output (Tensor[image_channels, image_height, image_width])