sksq96 / pytorch-summary

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

TypeError: apply() missing 1 required positional argument: 'fn' #19

Open mundher opened 6 years ago

mundher commented 6 years ago

I tried this code

from torchsummary import summary
summary(WideSeg, input_size=(1,640,512))

and I got this error message

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-6b714975e255> in <module>()
      1 from torchsummary import summary
----> 2 summary(WideSeg, input_size=(1,640,512))

~\Anaconda3\lib\site-packages\torchsummary\torchsummary.py in summary(model, input_size)
     51         hooks = []
     52         # register hook
---> 53         model.apply(register_hook)
     54         # make a forward pass
     55         # print(x.shape)

TypeError: apply() missing 1 required positional argument: 'fn'
sksq96 commented 5 years ago

Thanks

HeimingX commented 5 years ago

I also run into this typeError problem, have you fixed it?

KazukiChiyo commented 5 years ago

You need to first initialize the model object, i.e.:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = SegNet(in_channels=3, out_channels=16).to(device)

before making the summary(model, input_size=(3, 360, 480)) call.