错误:empty() received an invalid combination of arguments

empty() received an invalid combination of arguments:

  File "D:\software\Anaconda3\envs\Y5\lib\site-packages\torch\nn\modules\conv.py", line 444, in __init__
    super(Conv2d, self).__init__(
  File "D:\software\Anaconda3\envs\Y5\lib\site-packages\torch\nn\modules\conv.py", line 131, in __init__
    self.weight = Parameter(torch.empty(
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:
 * (tuple of ints size, *, tuple of names names, torch.memory_format memory_format, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
 * (tuple of ints size, *, torch.memory_format memory_format, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

让我们来看一下这段代码的错误行:

self.weight = Parameter(torch.empty(
    (out_channels, in_channels, kernel_size[0], kernel_size[1]),
    dtype=torch.float,
    device=self.device
))

其中之一的方案:

  • 检查 in_dim 和 hidden_dim 是否为有效整数:确保传入的 in_dim 和 hidden_dim 是有效的整数,且不是 None 或其他不合法的类型。
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值