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 或其他不合法的类型。