Table of Contents
Shortcuts

# FractionalMaxPool2d

class torch.nn.FractionalMaxPool2d(kernel_size, output_size=None, output_ratio=None, return_indices=False, _random_samples=None)

  Applies a 2D fractional max pooling over an input signal composed of several input planes.

  Fractional MaxPooling is described in detail in the paper Fractional MaxPooling by Ben Graham

  The max-pooling operation is applied in k H×k W kH \times kW k H×kW regions by a stochastic step size determined by the target output size. The number of output features is equal to the number of input planes.

  Note

  Exactly one of `output_size` or `output_ratio` must be defined.

  Parameters:

    - kernel_size (Union[int, Tuple[int, int]]) – the size of the window to take a max over. Can be a single number k (for a square kernel of k x k) or a tuple (kh, kw)

    - output_size (Union[int, Tuple[int, int]]) – the target output size of the image of the form oH x oW. Can be a tuple (oH, oW) or a single number oH for a square image oH x oH

    - output_ratio (Union[float, Tuple[float, float]]) – If one wants to have an output size as a ratio of the input size, this option can be given. This has to be a number or tuple in the range (0, 1)

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

  Shape:

    - Input: (N,C,H i n,W i n)(N, C, H_{in}, W_{in})(N,C,H in​,W in​) or (C,H i n,W i n)(C, H_{in}, W_{in})(C,H in​,W in​).

    - Output: (N,C,H o u t,W o u t)(N, C, H_{out}, W_{out})(N,C,H o u t​,W o u t​) or (C,H o u t,W o u t)(C, H_{out}, W_{out})(C,H o u t​,W o u t​), where (H o u t,W o u t)=output_size(H_{out}, W_{out})=\text{output\_size}(H o u t​,W o u t​)=output_size or (H o u t,W o u t)=output_ratio×(H i n,W i n)(H_{out}, W_{out})=\text{output\_ratio} \times (H_{in}, W_{in})(H o u t​,W o u t​)=output_ratio×(H in​,W in​).

  Examples

      >>> # pool of square window of size=3, and target output size 13x12
      >>> m = nn.FractionalMaxPool2d(3, output_size=(13, 12))
      >>> # pool of square window and target output size being half of input image size
      >>> m = nn.FractionalMaxPool2d(3, output_ratio=(0.5, 0.5))
      >>> input = torch.randn(20, 16, 50, 32)
      >>> output = m(input)

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.