ZJU-lishuang / yolov5_prune

yolov5 prune,Support V2, V3, V4 and V6 versions of yolov5
Apache License 2.0
556 stars 136 forks source link

'Model' object has no attribute 'module_list' 稀疏训练报错 #31

Closed syswyl closed 3 years ago

syswyl commented 3 years ago

按照作者的readme操作,下载的是官方v5的第四个版本的yolov5s,配置文件yolov5s.yaml是作者提供的,数据集yaml已修改。 在稀疏训练结束查看bn权重时候报错

Traceback (most recent call last): File "train_sparsity.py", line 663, in train(hyp, opt, device, tb_writer, wandb)
File "train_sparsity.py", line 530, in train
bn_weights = gather_bn_weights(model.module_list, [idx]) File "H:\Anaconda3\envs\yolov5-ss\lib\site-packages\torch\nn\modules\module.py", line 778, in getattr raise ModuleAttributeError("'{}' object has no attribute '{}'".format( torch.nn.modules.module.ModuleAttributeError: 'Model' object has no attribute 'module_list'

我的本地版本是

python 3.8.5 torch 1.7.1

我将模型打印输出,发现确实缺少了该部分,我参考了v3剪枝中的issue,但是没有解决。希望得到回复~ 这个问题似乎不会对训练产生影响,但是想知道问题出在哪儿,

ZJU-lishuang commented 3 years ago

bn_weights = gather_bn_weights(model.module_list, [idx]) 其中model改为cfg_model,这里笔误了

bn_weights = gather_bn_weights(cfg_model.module_list, [idx])

syswyl commented 3 years ago

bn_weights = gather_bn_weights(model.module_list, [idx]) 其中model改为cfg_model,这里笔误了

bn_weights = gather_bn_weights(cfg_model.module_list, [idx])

thanks~😀