permute_channels¶
- torchvision.transforms.v2.functional.permute_channels(inpt: Tensor, permutation: List[int]) Tensor [來源]¶
根據給定的排列,置換輸入的通道。
此函式支援純
Tensor
、PIL.Image.Image
,以及torchvision.tv_tensors.Image
和torchvision.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)
與輸入中的通道數量不符。