sksq96 / pytorch-summary

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

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same #52

Open forhonourlx opened 5 years ago

forhonourlx commented 5 years ago

Traceback (most recent call last): File "examples.py", line 566, in ppo_pixel_atari(game) File "examples.py", line 391, in ppo_pixel_atari run_steps(PPOAgent(config)) File "/home/simon/Desktop/DeepRL.old/deep_rl/agent/PPO_agent.py", line 25, in init torchsummary.summary(self.network,(4, 84, 84)) File "/home/simon/anaconda3/lib/python3.6/site-packages/torchsummary/torchsummary.py", line 72, in summary model(x) File "/home/simon/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(input, kwargs) File "/home/simon/Desktop/DeepRL.old/deep_rl/network/network_heads.py", line 173, in forward phi = self.network.phi_body(obs) File "/home/simon/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, *kwargs) File "/home/simon/Desktop/DeepRL.old/deep_rl/network/network_bodies.py", line 19, in forward y = F.relu(self.conv1(x)) File "/home/simon/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(input, kwargs) File "/home/simon/anaconda3/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 320, in forward self.padding, self.dilation, self.groups) RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

dc3ea9f commented 5 years ago

There are two ways to fix it:

  1. convert your network to cuda
  2. call torchsummary.summary with device='cpu'
ghost commented 5 years ago

https://github.com/sksq96/pytorch-summary/issues/36