Here takes yolov3 as an example to demonstrate how to convert your own model, adapt it to our demo, and run it on VIM3
NotePlease review the document carefully before converting the reference document
Prepare
Train your own yolov3 model. The training method and process can refer to the official: Darknet Yolo Page, here we use the officially trained weights based on the coco data set
Prepare SDK, app warehouse, and demo warehouse
Please refer to the SDK, app and demo documents respectively for how to obtain the corresponding code
Conversion
The conversion is performed under the SDK.
1 | cd {workspace}/SDK/acuity-toolkit/conversion_scripts |
Modify 0_import_model.sh
- Modify
NAME
1 | NAME=mobilenet_tf --> NAME=yolov3 |
- Comment out Tensorflow
1 | convert_tf \ |
Modify to,
1 | $convert_tf \ |
- Comment Darknet
1 | $convert_darknet \ |
Modify to,
1 | convert_darknet \ |
Modify 1_quantize_model.sh
- Modify
NAME
1 | NAME=mobilenet_tf --> NAME=yolov3 |
- Modify regression parameters
1 | --channel-mean-value '128 128 128 128' \ |
Modify to,
1 | --channel-mean-value '0 0 0 256' \ |
- Modify
validation_tf.txt
Replace the image inside
1 | cat ./data/validation_tf.txt |
Modify to,
1 | path/to/416x416.jpg |
The picture resolution here is the same as the configuration in the yolo cfg file
- Modify quant type
1 | --quantized-dtype asymmetric_affine-u8 \ |
Modify to,
1 | --quantized-dtype dynamic_fixed_point-i8 \ |
Modify 2_export_case_code.sh
- Modify
NAME
1 | NAME=mobilenet_tf --> NAME=yolov3 |
- Modify regression parameters
1 | --channel-mean-value '128 128 128 128' \ |
Modify to,
1 | --channel-mean-value '0 0 0 256' \ |
- Modify the RGB channel order
default channel is RGB
1 | --reorder-channel '0 1 2' \ |
Modified to BGR
1 | --reorder-channel '2 1 0' \ |
- Specified board model
VIM3
1 | --optimize VIPNANOQI_PID0X88 \ |
VIM3L
1 | --optimize VIPNANOQI_PID0X99 \ |
Compile And Get The Case Code
- Compile
1 | bash 0_import_model.sh && bash 1_quantize_model.sh && bash 2_export_case_code.sh |
- case code
The converted code is in the nbg_unify_yolov3
directory
1 | ls {workspace}/SDK/acuity-toolkit/conversion_scripts/nbg_unify_yolov3 |
Compile
This part of the code is carried out in the aml_npu_app warehouse. Enter the directory of detect_yolo_v3
1 | cd {workspace}/aml_npu_app/detect_library/model_code/detect_yolo_v3 |
Replace VNN File
- Replace
vnn_yolov3.h
,vnn_post_process.h
,vnn_pre_process.h
generated by SDK
1 | cp {workspace}/SDK/acuity-toolkit/conversion_scripts/nbg_unify_yolov3/vnn_yolov3.h {workspace}/aml_npu_app/detect_library/model_code/detect_yolo_v3/include/vnn_yolov3.h |
- Replace
vnn_yolov3.c
generated by SDK
1 | cp {workspace}/SDK/acuity-toolkit/conversion_scripts/nbg_unify_yolov3/vnn_yolov3.c {workspace}/aml_npu_app/detect_library/model_code/detect_yolo_v3/vnn_yolov3.c |
Modify yolov3_process.c
- Modify the class array
1 | static char *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"}; |
According to your training data set settings, if it is a coco data set, there is no need to modify it.
- Modify
yolo_v3_post_process_onescale
Modify num_class
1 | int num_class = 80; |
The num_class
here is the same as the number of classes in the training set
- Modified post-processing function
yolov3_postprocess
Modify num_class
and size[3]
1 | int num_class = 80; |
The num_class
here is the same as the number of classes in the training set
The size[2]
here is equal to (num_class + 5) * 3
Compile
Use the build_vx.sh
script to compile the yolov3 library,
1 | cd {workspace}/aml_npu_app/detect_library/model_code/detect_yolo_v3 |
The generated library is in the bin_r
directory
1 | ls {workspace}/aml_npu_app/detect_library/model_code/detect_yolo_v3/bin_r |
Run
Replace
- Replace yolov3 library
1 | cp {workspace}/aml_npu_app/detect_library/model_code/detect_yolo_v3/bin_r/libnn_yolo_v3.so {workspace}/aml_npu_demo_binaries/detect_demo_picture/lib/libnn_yolo_v3.so |
- Replace nb file
VIM3
1 | cp {workspace}/SDK/acuity-toolkit/conversion_scripts/nbg_unify_yolov3/yolov3.nb {workspace}/aml_npu_demo_binaries/detect_demo_picture/nn_data/yolov3_88.nb |
VIM3L
1 | cp {workspace}/SDK/acuity-toolkit/conversion_scripts/nbg_unify_yolov3/yolov3.nb {workspace}/aml_npu_demo_binaries/detect_demo_picture/nn_data/yolov3_99.nb |
Run with board
How to run the replaced aml_npu_demo_binaries
on the board, please refer to