vai_p_darknet Usage - 1.1 English

AI Optimizer User Guide (UG1333)

Document ID
UG1333
Release Date
2020-07-07
Version
1.1 English

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.

Table 1. Seven Commands in vai_p_darknet
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.
Usage:
./vai_p_darknet pruner ana cfg weights [-gpus gpu_ids]
Example:
./vai_p_darknet pruner ana pruning/cfg pruning/yolov3.weights -gpus 0,1,2,3
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.

Usage:
./vai_p_darknet pruner prune cfg weights
Example:
./vai_p_darknet pruner prune pruning/cfg pruning/yolov3.weights -gpus 0,1,2,3
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.
Usage:
./vai_p_darknet pruner finetune cfg [weights] [-gpus gpu_ids]
Example:
./vai_p_darknet pruner finetune pruning/cfg pruning/weights.prune -gpus 0,1,2,3
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.
Usage:
./vai_p_darknet pruner transform cfg weights
Example:
./vai_p_darknet pruner transform pruning/cfg backup/*_final.weights -gpus 0,1,2,3
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.
Usage
./vai_p_darknet pruner stat cfg
Example:
./vai_p_darknet pruner stat pruning/cfg
./vai_p_darknet pruner stat pruning/yolov3.cfg
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.
Usage
./vai_p_darknet pruner map cfg weights
Example:
./vai_p_darknet pruner map pruning/cfg backup/*_final.weights -gpus 0,1,2,3
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.
Usage
./vai_p_darknet pruner valid cfg weights [-out outfile]
Example:
./vai_p_darknet pruner valid pruning/cfg backup/*_final.weights -gpus 0,1,2,3
Table 2. Full list of Options in Main cfg File
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___