UpsamplingNearest2d¶
- class torch.nn.UpsamplingNearest2d(size=None, scale_factor=None)[source][source]¶
对由多个输入通道组成的输入信号应用 2D 最近邻上采样。
要指定缩放比例,它接受
size
或scale_factor
作为其构造函数参数。当给出
size
时,它是图像 (h, w) 的输出大小。- 参数
size (int 或 Tuple[int, int], 可选) – 输出空间大小
scale_factor (float 或 Tuple[float, float], 可选) – 空间大小的乘数。
警告
此类已弃用,推荐使用
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.]]]])