快捷鍵

permute_channels

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

根據給定的排列,置換輸入的通道。

此函式支援純 TensorPIL.Image.Image,以及 torchvision.tv_tensors.Imagetorchvision.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) 與輸入中的通道數量不符。

文件

獲取 PyTorch 的完整開發者文件

檢視文件

教學

取得為初學者和進階開發人員提供的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源