mindspore.nn.ChannelShuffle
- class mindspore.nn.ChannelShuffle(groups)[source]
Divide the channels in a tensor of shape
into group and rearrange them as , while retaining the original tensor shape in the final output.- Parameters
groups (int) – Number of groups to divide channels in, must be greater than 0. Refer to
in the above formula.
- Inputs:
x (Tensor) - Tensor of shape
.
- Outputs:
Tensor, with the same type and shape as the x.
- Raises
TypeError – If groups is not a positive integer.
ValueError – If groups is less than 1.
ValueError – If dims of x is less than 3.
ValueError – If number of channels can not be divisible by groups.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore as ms >>> import numpy as np >>> channel_shuffle = ms.nn.ChannelShuffle(2) >>> x = ms.Tensor(np.arange(16).astype(np.int32).reshape(1, 4, 2, 2)) >>> print(x) [[[[ 0 1] [ 2 3]] [[ 4 5] [ 6 7]] [[ 8 9] [10 11]] [[12 13] [14 15]]]] >>> output = channel_shuffle(x) >>> print(output) [[[[ 0 1] [ 2 3]] [[ 8 9] [10 11]] [[ 4 5] [ 6 7]] [[12 13] [14 15]]]]