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.