pytorch中layer和function的区别

本文讨论了在PyTorch中遇到的nn.functional.upsample被弃用的问题,并指出应使用nn.functional.interpolate。作者解释了用户对于layer和function困惑的情况,提出可以将function包装成layer以便在sequential模型中使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近遇到代码中的一个warining, UserWarning: nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.
  warnings.warn("nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.")

然后看到一个人的提问,“

I just need a layer, not a function.

If nn.Upsample is deprecated, i cannot find any layer to replace it.

F.upsample and F.interpolate may be similar, but there is no nn.Interpolate, and I don’t know why.

让我这个平时没有特别区别function和layer的用法的人一愣。。。

You could probably just wrap F.interpolate into a nn.Module ans still use it in your sequential model. Have a look at this for an example.

class Interpolate
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值