Author: Pedro Vinícius A. B. Venâncio1,2
1 Graduate Program in Electrical Engineering (PPGEE/UFMG)
2 Gaia, solutions on demand (GAIA)
This repository contains the source codes of some techniques for filter pruning in convolutional neural networks implemented in the Darknet framework. Pruning a trained network with an appropriate technique can slightly decrease its performance (or even improve it in some cases), in addition to making the network lighter and faster to run on mobile devices and machines without a Graphics Processing Unit (GPU). The pruning techniques implemented can be classified into three categories:
- Criteria-based pruning techniques: L0-Norm, L1-Norm, L2-Norm, L-Inf Norm and Random.
- Projection-based pruning techniques: PLS(Single)+VIP, PLS(Multi)+VIP, CCA(Multi)+CV and PLS(Multi)+LC.
- Cluster-based pruning techniques: HAC+PCC.
Note: If you do not want to reuse the filters that remained in the pruned architecture for fine-tuning, just use the From-Scratch mode.
After compiling Darknet on your machine, creating your .cfg and .data files and training your network, follow these steps:
- Download this repository within your
darknet/
folder:
git clone https://github.com/pedbrgs/Pruning-Darknet/ darknet/pruning/
-
After that, move all files and folders from
pruning/
to root directorydarknet/
. You can remove thepruning/
folder, which is empty now. -
Move the
.cfg
,.data
,.names
,.weights
,train.txt
andvalid.txt
files into the darknet repository. Make sure that you have already trained the network for the desired task and that the paths in.data
are correct.
Note: If you arrived here in this repository without ever training a network in the Darknet framework, I recommend that you learn how to use it first. You need to compile Darknet, define your deep network, define your dataset and train your model to proceed.
- Run pruning with fine-tuning:
- Example for a criterion-based method:
python prune.py --cfg yolo.cfg --data yolo.data --names yolo.names --weights yolo.weights --network YOLOv4 --img-size 416 --technique L1 --pruning-rate 0.60 --pruning-iter 2 --lr 0.005 --tuning-iter 30000
- Example for a projection-based method:
python prune.py --cfg yolo.cfg --data yolo.data --names yolo.names --weights yolo.weights --network YOLOv4 --img-size 416 --technique PLS-VIP-Multi --pruning-rate 0.60 --pruning-iter 2 --lr 0.005 --tuning-iter 30000 --pool-type max --n-components 2 --num-classes 3 --perc-samples 0.1
- Example for a cluster-based method:
python prune.py --cfg yolo.cfg --data yolo.data --names yolo.names --weights yolo.weights --network YOLOv4 --img-size 416 --technique HAC --pruning-rate 0.60 --pruning-iter 2 --lr 0.005 --tuning-iter 30000 --measure Pearson
- Darknet Manual
- Compile on Windows
- Compile on Linux/macOS
- Requirements (and how to install dependecies)
If you're using these codes in any way, please let them know your source:
@Misc{Venancio2021-Pruning,
title = {Pruning techniques of convolutional neural networks implemented in the Darknet framework},
author = {Pedro Vinicius A. B. Venancio},
howPublished = {\url{https://git.io/JmjNB}},
year = {2021}}
Please send any bug reports, questions or suggestions directly in the repository.