The pruning tool includes seven commands shown in Table 1. The ana
, prune
, finetune
, and transform
are main commands corresponding to the pruning process. The
stat
, map
,
and valid
commands are auxiliary tools. The main
cfg file is required for all the commands. A full list of options in the main cfg
file is shown in Table 1. The last column “Used in” shows this option is used in
which commands. Use the first character to represent the commands. For example, the
“workspace” option is used in all the commands, so “APFTSMV
” is there. “yolov3” is used only in the ana
and prune
commands, so “AP_____
” is in that column.
Command | Description and Usage |
---|---|
ana | Analyze the model to find the pruning strategy. This command analyzes
the input model (“modelcfg” in main cfg + weights in command line),
generate a prunedcfg file and output ana results. The default output
location is the “workspace” specified in cfg and the default file
names are {$prefix}-prune.cfg and
ana.out. Output file names can be changed
by specifying “prunedcfg” and “ana_out_file” in cfg. See Table 1 for all the items in main cfg.
Multiple GPUs can be used to accelerate the ana process by setting
the GPUs indices.
|
prune | Prune the input model. This command prunes the input model (“modelcfg”
in main cfg + weights in command line) according to the ana result
by ana command and the settings in
main cfg. The parameters include “criteria”, “kernel_batch”,
“ignore_layer”, “threshold” and “is_yolov3.” See Table 1 for
setting details.Generally, the prunedcfg file has been created in the ana step. If “prunedcfg” is not specified in main cfg, this command will generate one automatically to the default path. The output pruned weights file is defined by “prune_out_weights” in main cfg. If not defined, the default output is “weights.prune” in workspace.
|
finetune | Fine-tune the pruned model to improve the performance of the model.
This command finetunes the pruned model. It reads model description
specified by “prunedcfg” in main cfg. For weights file, weights file
in command line is the first priority. If not specified, the
“prune_out_weights” in main cfg is used. This finetune command
follows the standard Darknet training process and save model
snapshots to “backup” directory by
default.
|
transform | Transform the pruned model to a regular model.
After channel pruning, there are many zeros in the pruned model
(“prunedcfg” in main cfg + weights in command line). This transform
command removes useless zeros and change the pruned model to a
normal one. The output model cfg and model weights are specified by
“transform_out_cfg” and “transform_out_weights” in main cfg. If not
specified, “model-transform.cfg” and “weights.transform” are the
default file
names.
|
stat | Count how many floating-point operations are
required for the model. Only a modelcfg is required for this
command. In the command line, you can use main cfg with a “modelcfg”
item like the other commands. Or you can directly use modelcfg in
the command
line.
|
map | Test model (“modelcfg” in main cfg + weights in
command line) mAP using the built-in method. This mAP is used in our
tool and it is not run in the standard way. Use “valid” command to
generate detection results and calculate mAP using the standard
python
script.
|
valid | Predict using specified model and output standard
detection results. The results can be further used to evaluate mAP,
using the tools provided by different datasets. This command is the
same as “darknet detector valid” in the open source
Darknet.
|
Option | Description | Default Value | Active In |
---|---|---|---|
workspace | Workspace for pruning | “./pruning” |
APFTSMV
|
datacfg | Data cfg file, same to standard darknet | “./pruning/voc.data” |
A_F__MV
|
modelcfg | Model cfg file, describe the model structure | "" |
AP__SMV
|
prunedcfg | Model cfg file for pruned model, add some flags to the original modelcfg | "" |
APFT___
|
ana_out_file | ana output file | "./pruning/ana.out" |
AP_____
|
criteria | Criteria for sorting during prune. 0: sort by L1 norm; 1: sort by L2 norm | 0 |
AP_____
|
kernel_batch | Minimum number of channels to prune at a time | 2 |
AP_____
|
ignore_layer | Layers id, separate by “,”, that should not be pruned | "" |
AP_____
|
yolov3 | Flag for YOLOv3 | 1 |
AP_____
|
yolo_v3v4 | Flag for YOLOv3 or YOLOv4 | 1 |
AP_____
|
threshold | Threshold for pruning. Under the threshold, calculate the pruning rate of each layer. See example for more information. | 0.005 |
_P_____
|
prune_out_file | Output file for pruned weights. | "" |
_PF____
|
snapshot | Number of iterations during finetuning after which a model can be saved. | 4000 |
__F____
|
transform_out_cfg | Model cfg file for transformed model. | model-transform.cfg |
___T___
|
transform_out_weights | Weights file for transformed model. | weights.transform |
___T___
|