channel_shuffle

paddle.nn.functional. channel_shuffle ( x, groups, data_format='NCHW', name=None ) [source]

This API implements channel shuffle operation. See more details in api_nn_vision_ChannelShuffle .

Parameters
  • x (Tensor) – 4-D tensor, the data type should be float32 or float64.

  • groups (int) – Number of groups to divide channels in.

  • data_format (str) – The data format of the input and output data. An optional string of NCHW or NHWC. The default is NCHW. When it is NCHW, the data is stored in the order of [batch_size, input_channels, input_height, input_width].

  • name (str, optional) – Name for the operation (optional, default is None). Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

Rearranged tensor keeping the original tensor shape.

Return type

Out (Tensor)

Examples

import paddle
import paddle.nn.functional as F
x = paddle.arange(0, 0.6, 0.1, 'float32')
x = paddle.reshape(x, [1, 6, 1, 1])
# [[[[0.        ]],
#   [[0.10000000]],
#   [[0.20000000]],
#   [[0.30000001]],
#   [[0.40000001]],
#   [[0.50000000]]]]
y = F.channel_shuffle(x, 3)
# [[[[0.        ]],
#   [[0.20000000]],
#   [[0.40000001]],
#   [[0.10000000]],
#   [[0.30000001]],
#   [[0.50000000]]]]