AttributeError: 'tuple' object has no attribute 'size'
AttributeError: 'tuple' object has no attribute 'size'
class Net(torch.nn.Module):
def __init__(self):
super(Net, self).__init__()
self.lstm = nn.LSTM(input_size=M,
hidden_size=128,
num_layers=2,
batch_first=False,
)
self.out = nn.Linear(128, N)
self.seattention = SEAttention(channel=64,reduction=8)
def forward(self, inputs, hidden):
r_out, hidden = self.lstm(inputs, hidden)
hidden = self.seattention(hidden)
outputs = self.out(r_out[-1, :, :])
return outputs, hidden
Traceback (most recent call last):
File "D:\YU\资料\PSSE_Code-master\LSTM\IEEE14\IEEE142.py", line 571, in
main()
File "D:\YU\资料\PSSE_Code-master\LSTM\IEEE14\IEEE142.py", line 567, in main
pfm_test()
File "D:\YU\资料\PSSE_Code-master\LSTM\IEEE14\IEEE142.py", line 539, in pfm_test
outputs, hidden = estimator(inputs2, hidden)
File "C:\Users\22810\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
File "D:\YU\资料\PSSE_Code-master\LSTM\IEEE14\IEEE142.py", line 158, in forward
hidden = self.seattention(hidden)
File "C:\Users\22810\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\22810\AppData\Local\Programs\Python\Python38\lib\site-packages\fightingcv_attention\attention\SEAttention.py", line 36, in forward
b, c, _, _ = x.size()
AttributeError: 'tuple' object has no attribute 'size'
思路毫无头绪
解决这个问题
看上去你没有截到关键的信息,.size()在哪个地方