decode_avif¶
- torchvision.io.decode_avif(input: Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGED) Tensor [源代码]¶
将 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]) – 一个一维连续的 uint8 张量,包含 AVIF 图像的原始字节。
mode (str 或 ImageReadMode) – 要转换到的图像模式,例如“RGB”。默认为“UNCHANGED”。有关可用模式,请参见
ImageReadMode
。
- 返回:
解码后的图像(Tensor[图像通道, 图像高度, 图像宽度])