UserWarning: nn.Upsample is deprecated. Use nn.functional.interpolate instead

Pytorch中使用nn.Upsample警告问题:
①首先说明该警告不影响程序的正常运行
②nn.Upsample与nn.functional.interpolate在功能上没有区别,但使用方法却不一样,即简单的把nn.Upsample换成nn.functional.interpolate是不行的。区别在于nn.Upsample可以写在nn.Sequential内,而nn.functional.interpolate不行,它要写在forward中,因为需要传入输入。如果你的代码都是嵌套在nn.Sequential中,则可以通过③来解决
③构建Interpolate类

class Interpolate(nn.Module):
    def init(self, scale_factor, mode):
        super(Interpolate, self).__init__()
        self.interpolate = nn.functional.interpolate
        self.scale_factor = scale_factor
        self.mode = mode
    def forward(self, x):
        x = self.interpolate(x, scale_factor=self.scale_factor, mode=self.mode)
        return x
        
然后把nn.Upsample换成Interpolate就Ok了

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值