maxout

paddle.nn.functional. maxout ( x, groups, axis=1, name=None ) [source]

maxout activation.

Assumed the input shape is (N, Ci, H, W). The output shape is (N, Co, H, W). Then Co = Ci/groups and the operator formula is as follows:

\[\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}\]
Parameters
  • x (Tensor) – The input is 4-D Tensor with shape [N, C, H, W] or [N, H, W, C], the data type of input is float32 or float64.

  • groups (int, optional) – The groups number of maxout. groups specifies the index of channel dimension where maxout will be performed. This must be a factor of number of features. Default is 1.

  • axis (int, optional) – The axis along which to perform maxout calculations. It should be 1 when data format is NCHW, be -1 or 3 when data format is NHWC. If axis < 0, it works the same way as \(axis + D\) , where D is the dimensions of x . axis only supports 1, 3 or -1. Default is 1.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

A Tensor with the same data type as x .

Examples

import paddle
import paddle.nn.functional as F

x = paddle.rand([1, 2, 3, 4])
# [[[[0.5002636  0.22272532 0.17402348 0.2874594 ]
#    [0.95313174 0.6228939  0.7129065  0.7087491 ]
#    [0.02879342 0.88725346 0.61093384 0.38833922]]
#   [[0.5231306  0.03807496 0.91661984 0.15602879]
#    [0.666127   0.616567   0.30741522 0.24044901]
#    [0.7142536  0.7351477  0.31588817 0.23782359]]]]
out = F.maxout(x, groups=2)
# [[[[0.5231306  0.22272532 0.91661984 0.2874594 ]
#    [0.95313174 0.6228939  0.7129065  0.7087491 ]
#    [0.7142536  0.88725346 0.61093384 0.38833922]]]]