报错TypeError: new() received an invalid combination of arguments - got (float, float, int), but expec

报错内容:

File "E:/Users/DELL/Documents/pycharmProjects/SimVPv2/simvp/models/modeltestMANV2andCGUandTA.py", line 509, in __init__
    self.local_conv = nn.Conv1d(c,c,3,padding=1)
    
TypeError: new() received an invalid combination of arguments - got (float, float, int), but expected one of:
 * (*, torch.device device)
 * (torch.Storage storage)
 * (Tensor other)
 * (tuple of ints size, *, torch.device device)
      didn't match because some of the arguments have invalid types: (!float!, !float!, !int!)
 * (object data, *, torch.device device)
      didn't match because some of the arguments have invalid types: (!float!, !float!, !int!)

报错原因
注意到,出错代码为

self.local_conv = nn.Conv1d(c,c,3,padding=1)

而我的参数c是这样得到的:

c = n_feats/10 #n_feats为int型

在python3中,/ 表示除法, int / int = float,所以我的参数c实际上是float型的。但是nn.Conv1d要求channel类型为int

解决办法

c = n_feats/10 #n_feats为int型

改为

c = n_feats//10

参考自https://blog.csdn.net/qq_36852840/article/details/114702011

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值