AttributeError ‘torch.Size’ object has no attribute ‘numel’
问题描述
使用 torchstat 来统计神经网络中的参数量的时候,出现以下错误:
出错描述:使用torchstat 的stat方法 报错 AttributeError ‘torch.Size’ object has no attribute 'numel’
出错原因:版本不一致
问题处理
当时是直接 pip install torchstat 安装的 torchstat 包,没有考虑到目前环境中 pytorch 的版本,而上述问题就是因为安装的torchstat版本不支持已安装的pytorch版本
Pytorch 的版本是 0.4.1 , torchstat 为0.0.6版本才支持,需要更换版本信息
# 使用该命令安装的是当前最新版本0.0.7的torchstat
pip install torchstat
# 使用该命令安装0.0.6版本的torchstat工具解决了文中的报错
pip install torchstat==0.0.6
更换完成之后,再执行即可!
具体的版本支持情况,可以查看github网站,传送门 torchStat github