nn.Upsample
定义
import torch.nn as nn
import torch.nn.functional as F
nn.Upsample(size=None, scale_factor=None, mode='nearest', align_corners=None)
F.upsample(input, size=None, scale_factor=None, mode='nearest', align_corners=None)
参数
align_corners
上图是source pixel为44,上采样为target pixel为88的对齐和不对齐两种情况。当设置align_corners = True时,会对齐左上角元素,即输入的左上角元素是一定等于输出的左上角元素。
形状
或者指定输出的size(Wout)、size(Hout, Wout)、size(Dout, Hout, Wout)
nn.functional.interpolate
定义
Down/up samples the input to either the given size or the given scale_factor
import torch.nn.functional as F
F.interpolate(input, size=None, scale_factor=None, mode='nearest', align_corners=None, recompute_scale_factor=None)
参数
形状
或者指定输出的size(Wout)、size(Hout, Wout)、size(Dout, Hout, Wout)
Warning
warnings.warn(“nn.functional.upsample is deprecated(不赞成,反对). Use nn.functional.interpolate instead.”)
现在都建议使用interpolate方法实现上采样,所以尽量用interpolate