vai_p_darknet Usage - 2.0 English

Vitis AI Optimizer User Guide (UG1333)

Document ID
UG1333
Release Date
2022-01-20
Version
2.0 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 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.

Table 1. Commands in vai_p_darknet
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.

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 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.

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 the performance of the model. This command fine-tunes 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 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 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 the 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. Options in the Main cfg File
Option Description Default Value Active In
workspace Workspace for pruning. “./pruning” APFTSMV
datacfg Data cfg file. Same as standard Darknet. “./pruning/voc.data” A_F__MV
modelcfg Model cfg file. Describes the model structure. "" AP__SMV
prunedcfg Model cfg file for pruned model. Adds some flags to the original modelcfg. "" APFT___
ana_out_file ana output file. "./pruning/ana.out" AP_____
criteria Criteria for sorting during pruning. 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. 0.005 _P_____
prune_out_file Output file for pruned weights. "" _PF____
snapshot Number of iterations during fine-tuning 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___