Update 2021/10/4: adapt to the new version of yolov5
Channel-wise pruning of yolov5
Preparation:
-
Download yolov5
git clone https://github.com/ultralytics/yolov5 cd yolov5 git reset --hard 59aae85a7e40701bb872df673a6ef288e99a4ae3
-
Download this compatible Torch-Pruning
git clone https://github.com/VainF/Torch-Pruning cd Torch-Pruning git reset --hard ec12e0590aad28e607e1df9feb2baf60c8cda689
-
Copy
torch_pruning
toyolov5
-
Download this repo and copy to
yolov5
Usage:
- Sparse learning: train new model with
--sl_factor
, L1 loss will be add to weights of all batchnorm layers - Pruning:
python prune.py --shape [batchsize channel height width] --prob 0.1 --weights [xxx.pt] --save_path [xxx_pruned.pt]
, channels with a batchnorm weight that is higher than a threshold will be removed - Fine-tuning: train the pruned model with
--ft_pruned
Reference: