Rate this Page

FractionalMaxPool2d#

classtorch.nn.modules.pooling.FractionalMaxPool2d(kernel_size,output_size=None,output_ratio=None,return_indices=False,_random_samples=None)[source]#

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

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

The max-pooling operation is applied inkH×kWkH \times kW regions by a stochasticstep size determined by the target output size.The number of output features is equal to the number of input planes.

Note

Exactly one ofoutput_size oroutput_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 formoH x oW.Can be a tuple(oH, oW) or a single number oH for a square imageoH x oH.Note that we must havekH+oH1<=HinkH + oH - 1 <= H_{in} andkW+oW1<=WinkW + oW - 1 <= W_{in}

  • 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).Note that we must havekH+(output_ratio_HHin)1<=HinkH + (output\_ratio\_H * H_{in}) - 1 <= H_{in}andkW+(output_ratio_WWin)1<=WinkW + (output\_ratio\_W * W_{in}) - 1 <= W_{in}

  • return_indices (bool) – ifTrue, will return the indices along with the outputs.Useful to pass tonn.MaxUnpool2d(). Default:False

Shape:

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)