tanluren / yolov3-channel-and-layer-pruning

yolov3 yolov4 channel and layer pruning, Knowledge Distillation 层剪枝,通道剪枝,知识蒸馏
Apache License 2.0
1.5k stars 446 forks source link

RuntimeError: Given groups=1, weight of size [208, 201, 1, 1], expected input[16, 184, 40, 76] to have 201 channels, but got 184 channels instead #144

Open gq-song opened 3 years ago

gq-song commented 3 years ago

yolov4的darknet权重,经过稀疏训练, 稀疏训练的命令: python train.py --cfg cfg/yolov4-obj.cfg --data data/obj.data --weights weights/yolov4-obj_best.weights --epochs 400 --batch-size 2 -sr --s 0.001 --prune 1 之后对稀疏训练的权重,进行层和通道剪枝,命令如下: python layer_channel_prune.py --cfg cfg/yolov4-obj.cfg --data data/obj.data --weights weights/best.pt --shortcuts 8 --global_percent 0.6 --layer_keep 0.01 --img_size 608 剪枝结果和报错如下: now we prune shortcut layers and corresponding CBLs all shortcut_idx: [7, 17, 20, 30, 33, 36, 39, 42, 45, 48, 51, 61, 64, 67, 70, 73, 76, 79, 82, 92, 95, 98, 101] These shortcut layers and corresponding CBL will be pruned : [90, 91, 92, 59, 60, 61, 28, 29, 30, 62, 63, 64, 31, 32, 33, 65, 66, 67, 93, 94, 95, 34, 35, 36] Class Images Targets P R mAP F1: 100%|█████████████| 159/159 [03:51<00:00, 1.29s/it] all 2.54e+03 6.23e+03 0.000162 0.00936 1.64e-05 0.000319 simply mask the BN Gama of to_be_pruned CBL as zero, now the mAP is 0.0000 Class Images Targets P R mAP F1: 100%|█████████████| 159/159 [03:53<00:00, 1.30s/it] all 2.54e+03 6.23e+03 0.000162 0.00936 1.64e-05 0.000319 after transfering the offset of pruned CBL's activation, map is 1.641718400601087e-05 testing the final model Class Images Targets P R mAP F1: 0%| | 0/159 [00:00<?, ?it/s]/opt/conda/lib/python3.6/site-packages/torch/nn/functional.py:3112: UserWarning: The default behavior for interpolate/upsample with float scale_factor changed in 1.6.0 to align with other frameworks/libraries, and now uses scale_factor directly, instead of relying on the computed output size. If you wish to restore the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. warnings.warn("The default behavior for interpolate/upsample with float scale_factor changed "

Traceback (most recent call last): File "layer_channel_prune.py", line 280, in compact_model_metric2 = eval_model(compact_model2) File "layer_channel_prune.py", line 37, in eval_model = lambda model:test(model=model, cfg=opt.cfg, data=opt.data, batch_size=16, img_size=img_size) File "/usr/local/src/test.py", line 74, in test inf_out, train_out = model(imgs) # inference and training outputs File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/usr/local/src/models.py", line 236, in forward x = module(x) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py", line 117, in forward input = module(input) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 423, in forward return self._conv_forward(input, self.weight) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 420, in _conv_forward self.padding, self.dilation, self.groups) RuntimeError: Given groups=1, weight of size [208, 201, 1, 1], expected input[16, 184, 40, 76] to have 201 channels, but got 184 channels instead 貌似是yolov4的upsample不支持,这个怎么解决呢?

Building-max commented 3 years ago

老哥,你解决了吗?