permute_channels¶
- torchvision.transforms.v2.functional.permute_channels(inpt: Tensor, permutation: List[int]) Tensor [source]¶
Permute the channels of the input according to the given permutation.
This function supports plain
Tensor
’s,PIL.Image.Image
’s, andtorchvision.tv_tensors.Image
andtorchvision.tv_tensors.Video
.Example
>>> rgb_image = torch.rand(3, 256, 256) >>> bgr_image = F.permute_channels(rgb_image, permutation=[2, 1, 0])
- Parameters:
permutation (List[int]) –
Valid permutation of the input channel indices. The index of the element determines the channel index in the input and the value determines the channel index in the output. For example,
permutation=[2, 0 , 1]
takes
ìnpt[..., 0, :, :]
and puts it atoutput[..., 2, :, :]
,takes
ìnpt[..., 1, :, :]
and puts it atoutput[..., 0, :, :]
, andtakes
ìnpt[..., 2, :, :]
and puts it atoutput[..., 1, :, :]
.
- Raises:
ValueError – If
len(permutation)
doesn’t match the number of channels in the input.