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 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
2. The last column “Used in” in Tables 2 shows this option is used in which
commands. We use the first character to represent the commands. For example, the
“workspace” option is used in all the commands, so “APFTSMV
” is there. “is_yolov3” is used in command ana and prune, so
“AP_____
” is in that column.
Command | Description and Usage |
---|---|
ana | Analyze the model to find the pruning strategy.
This command will analyze 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 2 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 will prune 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 2 for setting details. Generally, 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 model’s
performance. This command will finetune 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 will be 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 | Prune at least how many channels at a time | 2 |
AP_____
|
ignore_layer | Not prune these layers id, separate by “,” | "" |
AP_____
|
is_yolov3 | Flag for YoloV3 | 1 |
AP_____
|
eval_images | How many images are used to evaluate mAP in our built-in function. -1 means using the whole validation dataset | -1 |
A____M_
|
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 | Save model after how many iterations during finetuning | 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___
|