torch.nn.functional中的interpolate插值函数

今年是农历牛年第一天,在家的生活不快乐,那边博客学习叭。

interpolate函数

def forward(self, input1, input2=[0,0,0,0]):
        out0 = F.relu(self.bn0(self.conv0(input1[0]+input2[0])), inplace=True)
        out0 = F.interpolate(out0, size=input1[1].size()[2:], mode='bilinear')
        out1 = F.relu(self.bn1(self.conv1(input1[1]+input2[1]+out0)), inplace=True)
        out1 = F.interpolate(out1, size=input1[2].size()[2:], mode='bilinear')
        out2 = F.relu(self.bn2(self.conv2(input1[2]+input2[2]+out1)), inplace=True)
        out2 = F.interpolate(out2, size=input1[3].size()[2:], mode='bilinear')
        out3 = F.relu(self.bn3(self.conv3(input1[3]+input2[3]+out2)), inplace=True)
        return out3

先放一段代码,大家不要晕,这是我第一次见到这个函数的使用。出现的场景是在如下图所示的模块结构的forward部分。
torch.nn.functional中的interpolate插值函数_第1张图片
不懂,那边挽起袖子加油干,查。

1、函数功能:实现一个插值功能,即常用的上采样和下采样。
2、插值种类:最近邻插值、线性差值和双线性插值等,包括基本数学中的差值方法。
3、函数输入:输入的张量可以具有多样性:2D、3D、4D等都可以选择,较为灵活。
4、函数参数:

参数 代表含义
input the input tensor
size output spatial size
scale_factor multiplier for spatial size
mode ‘nearest[default]’ ‘linear’ ‘bilinear’ ‘bicubic’ ‘trilinear’ ‘area’

函数运行:

#对于横轴X和纵轴y上来进行插值拟合
x_new=list(np.arange(0, 15, 0.5))
y_new=list(f(x_new))
plt.plot(x,y,'r',label='original values')
plt.plot(x_new,y_new,'b',label='interpolated values')
plt.show()
plt.close()

参考博客:https://blog.csdn.net/zhangjian2928/article/details/80310353

你可能感兴趣的:(python零散知识总结,python,深度学习)