Rate this Page
★ ★ ★ ★ ★

AdaptiveMaxPool1d#

class torch.nn.AdaptiveMaxPool1d(output_size, return_indices=False)[source]#

Applies a 1D adaptive max pooling over an input signal composed of several input planes.

The output size is LoutL_{out}, for any input size. The number of output features is equal to the number of input planes.

Each output element is the maximum over a region of the input whose bounds are derived from the input and output sizes:

start(k)=⌊k×LinLout⌋end(k)=⌈(k+1)×LinLout⌉\text{start}(k) = \left\lfloor \frac{k \times L_{in}}{L_{out}} \right\rfloor \qquad \text{end}(k) = \left\lceil \frac{(k + 1) \times L_{in}}{L_{out}} \right\rceil
out(Ni,Cj,k)=max⁡start(k)≤l<end(k)input(Ni,Cj,l)out(N_i, C_j, k) = \max_{\text{start}(k) \le l < \text{end}(k)} input(N_i, C_j, l)

When LinL_{in} is not divisible by LoutL_{out}, these regions may have different sizes and may overlap. For example, an input of size 5 pooled to size 3 uses the regions [0,2)[0, 2), [1,4)[1, 4) and [3,5)[3, 5).

Parameters:
  • output_size (int | tuple[int]) – the target output size LoutL_{out}.

  • return_indices (bool) – if True, will return the indices along with the outputs. Useful to pass to nn.MaxUnpool1d. Default: False

Shape:
  • Input: (N,C,Lin)(N, C, L_{in}) or (C,Lin)(C, L_{in}).

  • Output: (N,C,Lout)(N, C, L_{out}) or (C,Lout)(C, L_{out}), where Lout=output_sizeL_{out}=\text{output\_size}.

Examples

>>> # target output size of 5
>>> m = nn.AdaptiveMaxPool1d(5)
>>> input = torch.randn(1, 64, 8)
>>> output = m(input)
forward(input)[source]#

Runs the forward pass.