最近邻二维上采样
- 类torch.nn.UpsamplingNearest2d(size=None, scale_factor=None)[源代码]
-
对由多个输入通道组成的输入信号进行二维最近邻上采样。
要指定缩放比例,可以将
size
或scale_factor
作为构造函数的参数。当给定
size
时,表示输出图像的大小为(h, w)。- 参数
警告
此类已不推荐使用,建议使用
interpolate()
替代。- 形状:
-
-
输入: $(N, C, H_{in}, W_{in})$
-
输出为 $(N, C, H_{out}, W_{out})$
-
$H_{out} = \left\lfloor H_{in} \times \text{scale\_factor} \right\rfloor$$W_{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.]]]])