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)與輸入的通道數不匹配。