1、ValueError: optimizer got an empty parameter list
实质上就是**model.parameters()**为空
2、AttributeError: ‘DRPGAT’ object has no attribute ‘to’
说明模型DRPGAT初始化的时候没有继承module,原来我的初始化是:
class DRPGAT(object):
修改为:
class DRPGAT(nn.Module):
3、RuntimeError: mat1 and mat2 shapes cannot be multiplied (50x1 and 50x1)
使用了torch.matmul(a,b)
,目的是想要a和b两个矩阵的对应位相乘。
修改为
torch.mul(a,b)
4、ValueError: optimizer got an empty parameter list
实际是在
optimizer = Adam(params = model.parameters(), lr = param.lr)
model.parameters()
获取值为空.。
解决办法:
将模型例如con1d等写在模型初始化时候,即不在forward函数里面,而是在init函数里面。
5、RuntimeError:one of the variables needed for gradient computation has been modified.which is output 0 of LeakyReluBackward0, is at version 1; expected version 0 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient
报错位置:我出现问题的位置是在loss.backward()的之后.
原因:看了很多帖子,大多是因为出现了如下情况:x +=y,这个要更改成x = x+y。具体原因在于你在backward()的时候由于loss计算过程中的变量发生了改变,反向传播过程的时候他就蒙了,咋还变了?
所以记得更改如下:
- x +=y 更改为x =x+y
- 在上述基础上还不行,就x_1=x+y
- 注意如果在tensor中使用了x.add(y)或者x.add_(y)的情况,改为x_1=x+y(我的问题就是出现在了这里)