转torchscript报错:Expected a value of type ‘Tensor (inferred)‘ for argument ‘scale‘ but instead found t

3 篇文章 0 订阅
1 篇文章 0 订阅
在将PyTorch代码转化为 TorchScript 时遇到错误,问题在于`upsample`函数的`scale`参数预期为Tensor类型,但实际传入的是整数。解决方案是在函数定义时明确指定`scale`参数为整型,如`scale:int=1`。修改后的代码能正确处理整数缩放因子,确保了脚本转换的顺利进行。
摘要由CSDN通过智能技术生成


def _upsample(self, x, y, scale=1):
        _, _, H, W = y.size()
        return F.interpolate(x, size=(H // scale, W // scale), mode='bilinear',align_corners=True)

转torchscript格式时报如下错误:

Expected a value of type 'Tensor (inferred)' for argument 'scale' but instead found type 'int'.
Inferred 'scale' to be of type 'Tensor' because it was not annotated with an explicit type.

你若果确实要传整型,改成

def _upsample(self, x, y, scale:int=1):
        _, _, H, W = y.size()
        return F.interpolate(x, size=(H // scale, W // scale), mode='bilinear',align_corners=True)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值