maxout¶
maxout 激活层。
假设输入形状为(N, Ci, H, W),输出形状为(N, Co, H, W),则 \(Co=Ci/groups\) 运算公式如下:
\[\begin{split}&out_{si+j} = \max_{k} x_{gsi + sk + j} \\ &g = groups \\ &s = \frac{input.size}{num\_channels} \\ &0 \le i < \frac{num\_channels}{groups} \\ &0 \le j < s \\ &0 \le k < groups\end{split}\]
参数¶
axis (int,可选) - 指定通道所在维度的索引。当数据格式为 NCHW 时,axis 应该被设置为 1,当数据格式为 NHWC 时,axis 应该被设置为-1 或者 3。默认值为 1。
name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。
返回¶
Tensor
,数据类型同x
一致。
代码示例¶
>>> import paddle
>>> import paddle.nn.functional as F
>>> paddle.seed(2023)
>>> x = paddle.rand([1, 2, 3, 4])
>>> print(x)
Tensor(shape=[1, 2, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[[0.86583614, 0.52014720, 0.25960937, 0.90525323],
[0.42400089, 0.40641287, 0.97020894, 0.74437362],
[0.51785129, 0.73292869, 0.97786582, 0.04315904]],
[[0.42639419, 0.71958369, 0.20811461, 0.19731510],
[0.38424349, 0.14603184, 0.22713774, 0.44607511],
[0.21657862, 0.67685395, 0.46460176, 0.92382854]]]])
>>> out = F.maxout(x, groups=2)
>>> print(out)
Tensor(shape=[1, 1, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[[0.86583614, 0.71958369, 0.25960937, 0.90525323],
[0.42400089, 0.40641287, 0.97020894, 0.74437362],
[0.51785129, 0.73292869, 0.97786582, 0.92382854]]]])