Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PaddlePaddle Hackathon 2】24、为 Paddle 新增 nn.ChannelShuffle 组网 API #4501

Merged
merged 6 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/api/paddle/nn/ChannelShuffle_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. _cn_api_nn_ChannelShuffle:

ChannelShuffle
-------------------------------

.. py:function:: paddle.nn.ChannelShuffle(groups, data_format="NCHW", name=None)
该算子将一个形为 [N, C, H, W] 或是 [N, H, W, C] 的 Tensor 按通道分成 g 组,得到形为 [N, g, C/g, H, W] 或 [N, H, W, g, C/g] 的 Tensor,然后转置为 [N, C/g, g, H, W] 或 [N, H, W, C/g, g] 的形状,最后重塑为原来的形状。这样做可以增加通道间的信息流动,提高特征的重用率。详见张祥雨等人在 2017 年发表的论文 `ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices <https://arxiv.org/abs/1707.01083>`_ 。


参数
:::::::::
- **groups** (int) – 要把通道分成的组数。
- **data_format** (str,可选) – 数据格式,可选:NCHW 或 NHWC,默认为 NCHW,即(批大小,通道数,高度,宽度)的格式。
- **name** (str,可选) – 操作的名称(可选,默认值为 None),大多数情况下不需要设置此属性。更多信息请参见 :ref:`api_guide_Name`。

形状
:::::::::
- **x** (Tensor) – 默认形状为(批大小,通道数,高度,宽度),即 NCHW 格式的 4-D Tensor。其数据类型为 float32 或 float64。
- **out** (Tensor) – 其形状与数据类型均和输入相同。

返回
:::::::::
计算 ChannelShuffle 的可调用对象。

代码示例
:::::::::
COPY-FROM: paddle.nn.ChannelShuffle:ChannelShuffle-example
1 change: 1 addition & 0 deletions docs/api/paddle/nn/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ Vision层
:header: "API名称", "API功能"


" :ref:`paddle.nn.ChannelShuffle <cn_api_nn_ChannelShuffle>` ", "将一个形为[N, C, H, W]或是[N, H, W, C]的Tensor按通道分成g组,得到形为[N, g, C/g, H, W]或[N, H, W, g, C/g]的Tensor,然后转置为[N, C/g, g, H, W]或[N, H, W, C/g, g]的形状,最后重新排列为原来的形状"
" :ref:`paddle.nn.PixelShuffle <cn_api_nn_PixelShuffle>` ", "将一个形为[N, C, H, W]或是[N, H, W, C]的Tensor重新排列成形为 [N, C/r**2, H*r, W*r]或 [N, H*r, W*r, C/r**2] 的Tensor"
" :ref:`paddle.nn.Upsample <cn_api_paddle_nn_Upsample>` ", "用于调整一个batch中图片的大小"
" :ref:`paddle.nn.UpsamplingBilinear2D <cn_api_paddle_nn_UpsamplingBilinear2D>` ", "用于调整一个batch中图片的大小(使用双线性插值方法)"
Expand Down
26 changes: 26 additions & 0 deletions docs/api/paddle/nn/functional/channel_shuffle_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. _cn_api_nn_functional_channel_shuffle:


channel_shuffle
-------------------------------

.. py:function:: paddle.nn.functional.channel_shuffle(x, groups, data_format="NCHW", name=None)
该算子将一个形为 [N, C, H, W] 或是 [N, H, W, C] 的 Tensor 按通道分成 g 组,得到形为 [N, g, C/g, H, W] 或 [N, H, W, g, C/g] 的 Tensor,然后转置为 [N, C/g, g, H, W] 或 [N, H, W, C/g, g] 的形状,最后重塑为原来的形状。这样做可以增加通道间的信息流动,提高特征的重用率。详见张祥雨等人在 2017 年发表的论文 `ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices <https://arxiv.org/abs/1707.01083>`_ 。

.. note::
详细请参考对应的 `Class` 请参考: :ref:`cn_api_nn_ChannelShuffle`。

参数
:::::::::
- **x** (Tensor) – 当前算子的输入,其是一个形状为 [N, C, H, W] 的 4-D Tensor。其中 N 是批大小,C 是通道数,H 是输入特征的高度,W 是输入特征的宽度。其数据类型为 float32 或 float64。
- **groups** (int) – 要把通道分成的组数;
- **data_format** (str,可选) – 数据格式,可选:NCHW 或 NHWC,默认为 NCHW,即(批大小,通道数,高度,宽度)的格式。
- **name** (str,可选) – 操作的名称(可选,默认值为 None),大多数情况下不需要设置此属性。更多信息请参见 :ref:`api_guide_Name`。

返回
:::::::::
``Tensor``,调整过通道顺序的 Tensor,其数据类型与输入相同。

代码示例
:::::::::
COPY-FROM: paddle.nn.functional.channel_shuffle:channel_shuffle-example