【问题标题】:Getting error when using print() or summary() in pytorch to see the layers and weight dimensions in a Pytorch model在 pytorch 中使用 print() 或 summary() 来查看 Pytorch 模型中的层和权重尺寸时出错
【发布时间】:2020-08-04 17:18:40
【问题描述】:

在现有模型上使用打印时, 它不打印模型。相反,它显示: <function resnext101_32x8d at 0x00000178CC26BA68>

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

使用summary时,报错如下:

AttributeError: 'function' 对象没有属性 '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'

如何解决这些与printsummary 相关的问题?还有其他方法可以轻松查看所有 pytorch 层和模型拓扑吗?

【问题讨论】:

    标签: machine-learning neural-network pytorch conv-neural-network resnet


    【解决方案1】:

    models.resnext101_32x8d是类构造函数,需要调用构造函数,最后加括号即可。

    m1 = models.resnext101_32x8d()
    print(m1)
    

    【讨论】:

    • 好的。如何解决summary 的问题?总结是否提供不同的信息?这适用于“打印”。谢谢。
    • torchvision没有summary类,需要安装使用torchsummary(repo)。
    • 感谢您的回复。为什么对这个问题投反对票?这个问题似乎与这个论坛有关。
    猜你喜欢
    • 2021-09-13
    • 2018-06-12
    • 1970-01-01
    • 2020-08-23
    • 2020-09-03
    • 2020-02-19
    • 2018-12-31
    • 2021-10-02
    • 2019-03-28
    相关资源
    最近更新 更多