pytorch-summary icon indicating copy to clipboard operation
pytorch-summary copied to clipboard

summary error when nn.LSTM(batch_first=True)

Open forhonourlx opened this issue 6 years ago • 9 comments

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))

forhonourlx avatar Mar 11 '19 13:03 forhonourlx

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

PuYuQian avatar Mar 12 '19 06:03 PuYuQian

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'

forhonourlx avatar Mar 12 '19 13:03 forhonourlx

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!

PuYuQian avatar Mar 13 '19 05:03 PuYuQian

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?

RachelOwl avatar Aug 04 '20 15:08 RachelOwl

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

patel-zeel avatar Aug 06 '20 03:08 patel-zeel

Using SummaryX solved my probelm

RachelShalom avatar Aug 06 '20 07:08 RachelShalom

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".

sbrahma0 avatar Jan 12 '21 04:01 sbrahma0

Using SummaryX solved my probelm

Very helpful answer! It works nicely now!

https://github.com/nmhkahn/torchsummaryX

yuzzfeng avatar Dec 31 '21 12:12 yuzzfeng

Using SummaryX solved my probelm

Thank you very much!!!

Guosheng-Ye avatar May 18 '23 08:05 Guosheng-Ye