在 PyTorch 中,可以使用 torchsummary
库来实现对 PyTorch 模型的结构及参数统计的输出,其可以方便我们查看每层输入、输出的维度以及参数数量等信息。
安装 torchsummary
库:
pip install torchsummary
使用方法如下:
import torch
from torchsummary import summary
model = torch.nn.Sequential(
)
summary(model, (3, 32, 32))
其中,model
是需要查看的模型,(3, 32, 32)
表示模型的输入维度,即 C = 3,H = 32,W = 32。运行后可以看到所有层输入、输出的维度以及参数数量等信息。
有个大坑
AttributeError: ‘xxx’ object has no attribute ‘size’
AttributeError: ‘int’ object has no attribute ‘size’
类似错误
pip uninstall torchsummary
pip install torch-summary
解决问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)