Shortcuts

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, and torchvision.tv_tensors.Image and torchvision.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 at output[..., 2, :, :],

  • takes ìnpt[..., 1, :, :] and puts it at output[..., 0, :, :], and

  • takes ìnpt[..., 2, :, :] and puts it at output[..., 1, :, :].

Raises:

ValueError – If len(permutation) doesn’t match the number of channels in the input.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources