shuffle_channel

paddle.fluid.layers.shuffle_channel(x, group, name=None)[source]

This operator shuffles the channels of input x. It divide the input channels in each group into group subgroups, and obtain a new order by selecting element from every subgroup one by one.

Please refer to the paper https://arxiv.org/pdf/1707.01083.pdf

Given a 4-D tensor input with the shape (N, C, H, W):
    input.shape = (1, 4, 2, 2)
    input.data =[[[[0.1, 0.2],
                   [0.2, 0.3]],

                  [[0.3, 0.4],
                   [0.4, 0.5]],

                  [[0.5, 0.6],
                   [0.6, 0.7]],

                  [[0.7, 0.8],
                   [0.8, 0.9]]]]
    Given group: 2
    then we get a 4-D tensor out whth the same shape of input:
    out.shape = (1, 4, 2, 2)
    out.data = [[[[0.1, 0.2],
                  [0.2, 0.3]],

                 [[0.5, 0.6],
                  [0.6, 0.7]],

                 [[0.3, 0.4],
                  [0.4, 0.5]],

                 [[0.7, 0.8],
                  [0.8, 0.9]]]]
Parameters
  • x (Variable) – The input tensor variable. It should be a 4-D tensor with shape [N, C, H, W]

  • group (int) – Indicating the counts of subgroups, It should divide the number of channels.

Returns

the channels shuffling result is a tensor variable with the same shape and same type as the input.

Return type

out(Variable)

Raises

ValueError – If group is not an int type variable.

Examples

import paddle.fluid as fluid
input = fluid.data(name='input', shape=[None,4,2,2], dtype='float32')
out = fluid.layers.shuffle_channel(x=input, group=2)