简体   繁体   中英

Getting error when using print() or summary() in pytorch to see the layers and weight dimensions in a Pytorch model

When using print on an existing model, it doesn't print the model. Instead it shows: <function resnext101_32x8d at 0x00000178CC26BA68>

>>> import torch
>>> import torchvision.models as models 
>>> m1 = models.resnext101_32x8d
>>> print(m1)
<function resnext101_32x8d at 0x00000178CC26BA68>
>>>

When using summary , it gives the following error:

AttributeError: 'function' object has no attribute 'apply'

>>> import torch
>>> import torchvision.models as models 
>>> from torchvision import summary
>>> m1 = models.resnext101_32x8d
>>>
>>> summary(m1, (3, 224, 224))
 Traceback(most recent call last):
   File "<stdin>", line 1, in <module>
   File torchsummary.py, line 68, in summary
      model.apply(register_hook)
AttributeError: 'function' object has no attribute 'apply'

How to fix these issues related to print and summary ? Any other ways to easily see all pytorch layers and model topology?

models.resnext101_32x8d is the class constructor, you need to call the constructor, just add parentheses at the end.

m1 = models.resnext101_32x8d()
print(m1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM