midasklr / yolov5prune

553 stars 113 forks source link

KeyError: 'model.1.bn' #101

Open qiaoyukeji opened 2 years ago

qiaoyukeji commented 2 years ago

剪枝时报错,KeyError: 'model.1.bn',请问怎样解决呢

Test after prune ... 
YOLOv5   torch 1.10.0+cu102 CUDA:0 (NVIDIA GeForce RTX 2080 Ti, 11264MiB)

Suggested Gamma threshold should be less than 0.0703.
The corresponding prune ratio is 0.666, but you can set higher.
Gamma value that less than 0.0001 are set to zero!
==============================================================================================
|       layer name               |         origin channels     |         remaining channels  |
|       model.0.bn               |         16                  |         15                  |
|       model.1.conv.1           |         16                  |         15                  |
|       model.1.conv.5           |         16                  |         16                  |
|       model.2.conv.1           |         72                  |         72                  |
|       model.2.conv.4           |         72                  |         72                  |
|       model.2.conv.8           |         24                  |         24                  |
|       model.3.conv.1           |         88                  |         88                  |
|       model.3.conv.4           |         88                  |         88                  |
|       model.3.conv.8           |         24                  |         24                  |
|       model.4.conv.1           |         96                  |         68                  |
|       model.4.conv.4           |         96                  |         68                  |
|       model.4.conv.8           |         40                  |         40                  |
|       model.5.conv.1           |         240                 |         68                  |
|       model.5.conv.4           |         240                 |         68                  |
|       model.5.conv.8           |         40                  |         40                  |
|       model.6.conv.1           |         240                 |         42                  |
|       model.6.conv.4           |         240                 |         43                  |
|       model.6.conv.8           |         40                  |         40                  |
|       model.7.conv.1           |         120                 |         91                  |
|       model.7.conv.4           |         120                 |         91                  |
|       model.7.conv.8           |         48                  |         48                  |
|       model.8.conv.1           |         144                 |         68                  |
|       model.8.conv.4           |         144                 |         68                  |
|       model.8.conv.8           |         48                  |         48                  |
|       model.9.conv.1           |         288                 |         62                  |
|       model.9.conv.4           |         288                 |         62                  |
|       model.9.conv.8           |         96                  |         96                  |
|       model.10.conv.1          |         576                 |         68                  |
|       model.10.conv.4          |         576                 |         68                  |
|       model.10.conv.8          |         96                  |         96                  |
|       model.11.conv.1          |         576                 |         54                  |
|       model.11.conv.4          |         576                 |         54                  |
|       model.11.conv.8          |         96                  |         96                  |
|       model.12.bn              |         256                 |         236                 |
|       model.15.cv1.bn          |         128                 |         124                 |
|       model.15.cv2.bn          |         128                 |         109                 |
|       model.15.cv3.bn          |         256                 |         197                 |
|       model.15.m.0.cv1.bn      |         128                 |         127                 |
|       model.15.m.0.cv2.bn      |         128                 |         119                 |
|       model.16.bn              |         128                 |         128                 |
|       model.19.cv1.bn          |         64                  |         64                  |
|       model.19.cv2.bn          |         64                  |         64                  |
|       model.19.cv3.bn          |         128                 |         128                 |
|       model.19.m.0.cv1.bn      |         64                  |         64                  |
|       model.19.m.0.cv2.bn      |         64                  |         64                  |
    run_prune(**vars(opt))
  File "C:\Adata\soft\soft_install\anaconda\envs\deepsort\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "prune.py", line 487, in run_prune
    pruned_model = ModelPruned(maskbndict=maskbndict, cfg=pruned_yaml, ch=3).cuda()
  File "C:\Adata\project\deeplearn\yolo\yolov5_6\yolov5_60\yolov5prune\models\yolo.py", line 263, in __init__
    self.model, self.save, self.from_to_map = parse_pruned_model(self.maskbndict, deepcopy(self.yaml), ch=[ch])  # model, savelist
  File "C:\Adata\project\deeplearn\yolo\yolov5_6\yolov5_60\yolov5prune\models\yolo.py", line 478, in parse_pruned_model
    bnc = int(maskbndict[named_m_bn].sum())
KeyError: 'model.1.bn'
qiaoyukeji commented 2 years ago

yolov5 的主干网络换成了 MobileNetV3 ,然后报错的

huochen1 commented 2 years ago

yolov5 的主干网络换成了 MobileNetV3 ,然后报错的

请问解决了吗

xinxin342 commented 2 years ago

我出现这个错误,你解决了吗? Traceback (most recent call last): File "D:\ProgramData\Anaconda3\envs\yolov5\yolov5prune-6.0\prune.py", line 806, in main(opt) File "D:\ProgramData\Anaconda3\envs\yolov5\yolov5prune-6.0\prune.py", line 779, in main run_prune(*vars(opt)) File "D:\ProgramData\Anaconda3\envs\yolov5\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context return func(args, **kwargs) File "D:\ProgramData\Anaconda3\envs\yolov5\yolov5prune-6.0\prune.py", line 537, in run_prune out_idx = np.squeeze(np.argwhere(np.asarray(maskbndict[layername[:-4] + "bn"].cpu().numpy()))) KeyError: 'model.0.act.depth_bn'

huochen1 commented 2 years ago

收到,谢谢

XsCai-sjtu commented 2 years ago

请问你解决了嘛

huochen1 commented 2 years ago

收到,谢谢

gudugududu commented 1 year ago

yolov5 的主干网络换成了 MobileNetV3 ,然后报错的

请问解决了吗

huochen1 commented 1 year ago

收到,谢谢

kkkkkid commented 1 year ago

请问您是如何解决的呀

huochen1 commented 1 year ago

收到,谢谢

holdon1997 commented 9 months ago

请问楼主解决了?

huochen1 commented 9 months ago

收到,谢谢