permute_channels¶
- torchvision.transforms.v2.functional.permute_channels(inpt: Tensor, permutation: List[int]) Tensor[源代码]¶
根据给定的排列顺序重新排列输入的通道。
此函数支持普通
Tensor、PIL.Image.Image以及torchvision.tv_tensors.Image和torchvision.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)与输入中的通道数不匹配。