sksq96 / pytorch-summary

Model summary in PyTorch similar to `model.summary()` in Keras
MIT License
3.98k stars 412 forks source link

summary error when nn.LSTM(batch_first=True) #56

Open forhonourlx opened 5 years ago

forhonourlx commented 5 years ago

File "C:\Users\simon\Desktop\DeepRL.old\deep_rl\agent\PPO_agent.py", line 25, in init torchsummary.summary(self.network,(100, 2, 11)) ...... File "C:\Users\simon\Desktop\DeepRL.old\deep_rl\network\network_bodies.py", line 149, in forward y, (h_n,c_n) = self.lstm1(x) File "C:\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 491, in call hook_result = hook(self, input, result) File "C:\Anaconda\lib\site-packages\torchsummary\torchsummary.py", line 23, in hook [-1] + list(o.size())[1:] for o in output File "C:\Anaconda\lib\site-packages\torchsummary\torchsummary.py", line 23, in [-1] + list(o.size())[1:] for o in output AttributeError: 'tuple' object has no attribute 'size'

where: self.lstm1 = nn_init(nn.LSTM(input_size=self.trace_length, hidden_size=self.n_lstm_units,batch_first=True))

PuYuQian commented 5 years ago

Hi,I solve this question#11,have a try!

forhonourlx commented 5 years ago

Hi Puyu, Thank you. But nn.LSTM(batch_first=True) still returns a tuple.

File "C:\Users\simon\Desktop\DeepRL.old\deep_rl\agent\PPO_agent.py", line 25, in init torchsummary.summary(self.network,(100, 2, 11)) File "C:\Anaconda\lib\site-packages\torchsummary\torchsummary.py", line 89, in summary model(x) File "C:\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 489, in call result = self.forward(input, *kwargs) File "C:\Users\simon\Desktop\DeepRL.old\deep_rl\network\network_heads.py", line 173, in forward phi = self.network.phi_body(obs) File "C:\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 489, in call result = self.forward(input, **kwargs) File "C:\Users\simon\Desktop\DeepRL.old\deep_rl\network\network_bodies.py", line 149, in forward y, (h_n,c_n) = self.lstm1(x)#(torch.Size([22, 8]), torch.Size([22, 8])), (torch.Size([1, 2, 8]), torch.Size([1, 2, 8])) File "C:\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 491, in call hook_result = hook(self, input, result) File "C:\Anaconda\lib\site-packages\torchsummary\torchsummary.py", line 37, in hook [-1] + list(o.size())[1:] for o in output File "C:\Anaconda\lib\site-packages\torchsummary\torchsummary.py", line 37, in [-1] + list(o.size())[1:] for o in output AttributeError: 'tuple' object has no attribute 'size'

PuYuQian commented 5 years ago

Hi, I think that you don't replace this version of pytorch-summary to Bond-SYSU/pytorch-summary successfully.When I do this,this error doesn't appear.Have a try!

RachelOwl commented 3 years ago

Hi, I actually have the exact same error with lstm and torchsummary and replacing the version didn't help. any ideas on how to solve this?

patel-zeel commented 3 years ago

I couldn't pass multiple inputs to Bond-SYSU version.

RachelShalom commented 3 years ago

Using SummaryX solved my probelm

sbrahma0 commented 3 years ago

Using SummaryX solved my probelm

Can you please share the link? Because I either get the error mentioned above or "input must have 3 dimensions, got 4".

yuzzfeng commented 2 years ago

Using SummaryX solved my probelm

Very helpful answer! It works nicely now!

https://github.com/nmhkahn/torchsummaryX

Guosheng-Ye commented 1 year ago

Using SummaryX solved my probelm

Thank you very much!!!