yolov5prune icon indicating copy to clipboard operation
yolov5prune copied to clipboard

prune

Open lijain opened this issue 3 years ago • 2 comments

在 yolov5 工程中使用yolov5m6.yaml训练。 使用 train_sparsity.py 进行训练,最终可以得到非常小的参数文件。 python train.py --adam --epochs 100 python train_sparsity.py --st --sr 0.0001 --weights runs/train/exp/lest.pt --adam --epochs 100 训练完成后进行剪枝 python prune.py --weights runs/train/exp1/weights/last.pt --percent 0.3 到这里无法进行下去了,出现的问题如下: Fusing layers... Model Summary: 396 layers, 35439396 parameters, 0 gradients, 51.4 GFLOPS prune module : dict_keys([]) model_list: {} bn_weights: tensor([]) prune.py:382: UserWarning: This overload of nonzero is deprecated: nonzero() Consider using one of the following signatures instead: nonzero(*, bool as_tuple) (Triggered internally at /opt/conda/conda-bld/pytorch_1603729066392/work/torch/csrc/utils/python_arg_parser.cpp:882.) percent_limit = (sorted_bn == highest_thre).nonzero()[0, 0].item() / len(bn_weights) Traceback (most recent call last): File "prune.py", line 818, in opt=opt File "prune.py", line 382, in test_prune percent_limit = (sorted_bn == highest_thre).nonzero()[0, 0].item() / len(bn_weights) IndexError: index 0 is out of bounds for dimension 0 with size 0 不知道是什么原因,麻烦你看下。 非常感谢!

lijain avatar Jun 18 '21 07:06 lijain

Fusing layers...

你这边报了Fusing layers...的log,应该是把conv和bn层进行融合了,剪枝是根据bn层进行的。不能进行model.fuse()操作

midasklr avatar Jun 19 '21 10:06 midasklr

不做融合的话... 最后参数量以及 计算量FLOPS 不计算啊

suhanling avatar Nov 23 '21 11:11 suhanling