UpsamplingNearest2d¶
- class torch.nn.UpsamplingNearest2d(size=None, scale_factor=None)[source][source]¶
对由多个输入通道组成的输入信号应用二维最近邻上采样。
为了指定比例,它接受
size
或scale_factor
作为其构造函数参数。当给出
size
时,它是图像的输出尺寸 (h, w)。- 参数
警告
此类已被弃用,请改用
interpolate()
。- 形状
输入: ,其中
输出: ,其中
示例
>>> 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.]]]])