快捷方式

permute_channels

torchvision.transforms.v2.functional.permute_channels(inpt: Tensor, permutation: list[int]) Tensor[source]

根据给定的排列顺序排列输入通道。

此函数支持纯 TensorPIL.Image.Image 以及 torchvision.tv_tensors.Imagetorchvision.tv_tensors.Video

示例

>>> rgb_image = torch.rand(3, 256, 256)
>>> bgr_image = F.permute_channels(rgb_image, permutation=[2, 1, 0])
参数:

permutation (List[int]) –

输入通道索引的有效排列。元素索引决定输入中的通道索引,而值决定输出中的通道索引。例如,permutation=[2, 0 , 1]

  • ìnpt[..., 0, :, :] 放在 output[..., 2, :, :]

  • ìnpt[..., 1, :, :] 放在 output[..., 0, :, :],以及

  • ìnpt[..., 2, :, :] 放在 output[..., 1, :, :]

抛出:

ValueError – 如果 len(permutation) 与输入的通道数不匹配。

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源