ChannelShuffle#
- class torch.nn.modules.channelshuffle.ChannelShuffle(groups)[source]#
分割並重新排列張量中的通道。
此操作將形狀為 的張量的通道劃分為 g 組,形式為 ,並對它們進行洗牌,同時保持原始張量形狀作為最終輸出。
- 引數
groups (int) – 要劃分通道的組數。
示例
>>> channel_shuffle = nn.ChannelShuffle(2) >>> input = torch.arange(1, 17, dtype=torch.float32).view(1, 4, 2, 2) >>> input tensor([[[[ 1., 2.], [ 3., 4.]], [[ 5., 6.], [ 7., 8.]], [[ 9., 10.], [11., 12.]], [[13., 14.], [15., 16.]]]]) >>> output = channel_shuffle(input) >>> output tensor([[[[ 1., 2.], [ 3., 4.]], [[ 9., 10.], [11., 12.]], [[ 5., 6.], [ 7., 8.]], [[13., 14.], [15., 16.]]]])