To use your own models, your model
framework should be within the scope of the Vitis AI
Library. This section shows you how to deploy a retrained YOLOv3 Caffe model to the
ZCU102 platform based on the Vitis AI
Library.
- Download the corresponding Docker image from https://github.com/Xilinx/Vitis-AI.
- Load and run the Docker.
- Create a folder and place the float model within it on the host side, then use the Vitis AI Quantizer to quantize the model. For more details, see the Vitis AI User Guide (UG1414).
- Use the Vitis AI Compiler to compile the model to an xmodel file, such as yolov3_custom.xmodel. For more information, see the Vitis AI User Guide (UG1414).
- Create the yolov3_custom.prototxt, as
shown in the following
snippet.
model { name: "yolov3_custom" kernel { name: "yolov3_custom" mean: 0.0 mean: 0.0 mean: 0.0 scale: 0.00390625 scale: 0.00390625 scale: 0.00390625 } model_type : YOLOv3 yolo_v3_param { num_classes: 20 anchorCnt: 3 layer_name: "59" layer_name: "67" layer_name: "75" conf_threshold: 0.3 nms_threshold: 0.45 biases: 10 biases: 13 biases: 16 biases: 30 biases: 33 biases: 23 biases: 30 biases: 61 biases: 62 biases: 45 biases: 59 biases: 119 biases: 116 biases: 90 biases: 156 biases: 198 biases: 373 biases: 326 test_mAP: false } }
Note: The <model_name>.prototxt file is effective only when you use the Vitis AI Library API_1.The parameter of the model needs to be loaded and read manually by the program when using the Vitis AI Library API_2. See the Vitis-AI/examples/vai_library/samples/dpu_task/yolov3/demo_yolov3.cpp file for details.
- Create the demo_yolov3.cpp file. See the Vitis-AI/examples/vai_library/samples/dpu_task/yolov3/demo_yolov3.cpp file for reference.
- Create a build.sh file as shown below,
or copy one from the Vitis AI Library demo
and modify it.
#/bin/sh CXX=${CXX:-g++} $CXX -std=c++17 -O3 -I. -o demo_yolov3 demo_yolov3.cpp -lopencv_core -lopencv_video -lopencv_videoio -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lglog -lxnnpp-xnnpp -lvitis_ai_library-model_config -lprotobuf -lvitis_ai_library-dpu_task
- Exit the Docker tool system and start the Docker runtime system.
- Cross-compile the program and generate an executable file called demo_yolov3.
sh -x build.sh
- Create a model folder in the /usr/share/vitis_ai_library/models folder on the target
side.
mkdir yolov3_custom /usr/share/vitis_ai_library/models
Note: /usr/share/vitis_ai_library/models is the default location for the program to read the model. You can also place the model folder in the same directory as the executable program. - Copy the yolov3_custom.xmodel and the
yolov3_custom.prototxt files to the target and put them
in the /usr/share/vitis_ai_library/models/yolov3_custom
location.
scp yolov3_custom.xmodel yolov3_custom.prototxt root@IP_OF_BOARD:/usr/share/vitis_ai_library/models/yolov3_custom
- Copy the executable program to the target board using scp.
scp demo_yolov3 root@IP_OF_BOARD:~/
- Execute the program on the target board to get the following results. Before
running the program, ensure that the target board has the Vitis AI Library installed, and prepare the images
you want to
test.
./demo_yolov3 yolov3_custom sample.jpg