yolov5prune
yolov5prune copied to clipboard
prune
在 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
Fusing layers...
你这边报了Fusing layers...的log,应该是把conv和bn层进行融合了,剪枝是根据bn层进行的。不能进行model.fuse()操作
不做融合的话... 最后参数量以及 计算量FLOPS 不计算啊