The training completed model is based on the corresponding framework. Although most of the frameworks have C / C + + interfaces, even if these interfaces are used, only CPU or GPU can be used. If you want to use NPU acceleration, you need to convert the trained model into NPU accelerated model code through SDK. This document mainly introduces how to adapt our model on SDK.
Note: The following examples take the trained object detection model of khadas as an example.
Apply for SDK
About the trainsform SDK, you need to apply with our website. After filling in the information, it will be sent to your email.
1 | $ cd Tool/acuity-toolkit-binary-5.0.0/conversion_scripts/ |
How to use Trainsform tool
0_import_model.sh
Parameter setting
NAME
isyolovX
--net-input
is path to yolovX-voc.cfg file--weight-input
is path to weights file
example:NAME=yolov3
--net-input /home/khadas/Pictures/VOCdevkit/yolov3-train/yolov3-voc.cfg \
--weight-input /home/khadas/Pictures/VOCdevkit/yolov3-train/backup/yolov3-voc_final.weights \
1_quantize_model.sh
Parameter setting
NAME
isyolovX
--source-file
is path to Validation file--channel-mean-value
set to0 0 0 256
--quantized-dtype
set todynamic_fixed_point-8
example:
NAME=yolov3
--channel-mean-value '0 0 0 256' \
--quantized-dtype dynamic_fixed_point-8 \
2_export_case_code.sh
Parameter setting
NAME
isyolovX
--reorder-channel
RGB color channel order changed to BGR2 1 0
--channel-mean-value
set ot0 0 0 256
--export-dtype
set toquantized
example:
NAME=yolov3
--reorder-channel '2 1 0' \
--channel-mean-value '0 0 0 256' \
--export-dtype quantized \
Run The trainform shell script
1 | $ cd acuity-toolkit-binary-5.0.0/conversion_scripts/ |
After conversion, In directory acuity-toolkit-binary-5.0.0/conversion_scripts/
, a file with the same name as the script will be generated. These files are the basic files after conversion.
Apply your own converted code
Download aml_npu_app and aml_npu_demo_binaries
1 | $ cd $workspace |
After the download is complete, there will be two directories: aml_npu_app
and aml_npu_binaries
File replacement
1 | $ cd $workspace/aml_npu_app/DDK_6.3.3.4/detect_library/model_code/detect_yolo_v3/ |
- Copy the
yolov3.nb
file converted by the conversion tool and replace theyolov3.nb
file in theNN data
directory - Replace
vnn_yolov3.c
converted by the conversion tool withvnn_yolov3.c
in DDK directory. - Copy the
vnn_yolov3.h
file converted by the conversion tool and replace thevnn_yolov3.h
file underinclude
edit file
1 | $ vim yolovX_process.c |
Modify 3 places
- The content of
*coco_names[]
is modified to the class of your training model. The order should be the same as the names file when you train. - Change the value of
num_class
to the size of your training class. - change the lastest value of
size[3]
to(num_class+5)*3
example:
*coco_names[] = ["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "sofa", "pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush", "Edge-V", "Edge", "VIM1", "VIM2", "VIM3", "VIM3L", "Fan3705", "Captain", "Captain+Edge", "ToneBoard", "Heatsink(VIMs)", "Heatsink(Edge)];
num_class=92
int size[3]={nn_width/32, nn_height/32,97*3};
Build the source code
1 | $ cd workspace/aml_npu_app/DDK_6.3.3.4/detect_library/model_code/detect_yolo_v3/ |
After compiling the corresponding yolov3 directory, the generated .so
file will be found in the bin_r
directory.
Replace demo file
1 | $ cd $workspace/aml_npu_demo_binaries/detect_demo/ |
Replace two places:
- Copy the so file generated in the previous step and replace it with
lib
. - Copy the Nb file in the previous step and replace the file in
nn_data
.1
2$ cp workspace/aml_npu_app/DDK_6.3.3.4/detect_library/model_code/detect_yolo_v3/bin_dir/libnn_yolo_v3.so $workspace/aml_npu_demo_binaries/detect_demo/lib/libnn_yolo_v3.so
$ cp workspace/aml_npu_app/DDK_6.3.3.4/detect_library/model_code/detect_yolo_v3/nn_data/yolov3_88.nb $workspace/aml_npu_demo_binaries/detect_demo/n_data/yolov3_88.nb
After the demo is completed, you can run your own Model.