Rate this Page

UpsamplingNearest2d#

classtorch.nn.UpsamplingNearest2d(size=None,scale_factor=None)[source]#

Applies a 2D nearest neighbor upsampling to an input signal composed of several input channels.

To specify the scale, it takes either thesize or thescale_factoras it’s constructor argument.

Whensize is given, it is the output size of the image(h, w).

Parameters
  • size (int orTuple[int,int],optional) – output spatial sizes

  • scale_factor (float orTuple[float,float],optional) – multiplier forspatial size.

Warning

This class is deprecated in favor ofinterpolate().

Shape:
Hout=Hin×scale_factorH_{out} = \left\lfloor H_{in} \times \text{scale\_factor} \right\rfloor
Wout=Win×scale_factorW_{out} = \left\lfloor W_{in} \times \text{scale\_factor} \right\rfloor

Examples:

>>>input=torch.arange(1,5,dtype=torch.float32).view(1,1,2,2)>>>inputtensor([[[[1., 2.],          [3., 4.]]]])>>>m=nn.UpsamplingNearest2d(scale_factor=2)>>>m(input)tensor([[[[1., 1., 2., 2.],          [1., 1., 2., 2.],          [3., 3., 4., 4.],          [3., 3., 4., 4.]]]])