Table of Contents
Shortcuts

# permute_channels

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

  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.permutate_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

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.