decode_avif¶
- torchvision.io.decode_avif(input: Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGED) Tensor [source]¶
将 AVIF 图像解码为 3 维 RGB[A] 张量。
警告
为了启用 torchvision 的 AVIF 解码功能,您首先需要运行
pip install torchvision-extra-decoders
。只需安装该包,您无需更新代码。此功能仅在 Linux 上受支持,并且仍处于 BETA 阶段。如有任何问题,请告知我们:https://github.com/pytorch/vision/issues/new/choose。请注意,torchvision-extra-decoders 是根据 LGPL 许可证发布的。大多数图像的输出张量值为 uint8 类型,范围在 [0, 255] 内。如果图像的位深大于 8,则输出张量为 uint16 类型,范围在 [0, 65535] 内。由于 pytorch 对 uint16 的支持有限,我们建议在此函数之后调用
torchvision.transforms.v2.functional.to_dtype()
并设置scale=True
,以便将解码后的图像转换为 uint8 或 float 张量。- 参数:
input (Tensor[1]) – 包含 AVIF 图像原始字节的一维连续 uint8 张量。
mode (str or ImageReadMode) – 图像转换模式,例如 “RGB”。默认值为 “UNCHANGED”。有关可用模式,请参阅
ImageReadMode
。
- 返回:
解码后的图像 (Tensor[image_channels, image_height, image_width])