快捷方式

UpsamplingNearest2d

class torch.nn.UpsamplingNearest2d(size=None, scale_factor=None)[source][source]

對由多個輸入通道組成的輸入訊號應用二維最近鄰上取樣。

為了指定比例,它接受 sizescale_factor 作為其建構函式引數。

當給出 size 時,它是影像的輸出尺寸 (h, w)

引數
  • size (intTuple[int, int], 可選) – 輸出空間尺寸

  • scale_factor (floatTuple[float, float], 可選) – 空間尺寸的乘數。

警告

此類已被棄用,請改用 interpolate()

形狀
  • 輸入: (N,C,Hin,Win)(N, C, H_{in}, W_{in}),其中

  • 輸出: (N,C,Hout,Wout)(N, C, H_{out}, W_{out}),其中

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

示例

>>> input = torch.arange(1, 5, dtype=torch.float32).view(1, 1, 2, 2)
>>> input
tensor([[[[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.]]]])

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲取問題解答

檢視資源