Developing with Vitis AI API_3 (Graph Runner) - 2.0 English

Vitis AI Library User Guide (UG1354)

Document ID
UG1354
Release Date
2022-01-20
Version
2.0 English
If the model is split into multiple subgraphs, you can no longer automatically run it with API_0, API_1, and API_2. You have to deploy the model subgraph by subgraph. Graph runner is the new API for deploying models. It converts the model into a single graph and makes deployment easier for models with multiple subgraphs.
  1. Git clone the corresponding Vitis AI Library from https://github.com/Xilinx/Vitis-AI.
  2. Install the cross-compilation system on the host side. Refer to Installation for instructions.
  3. Check the model to see if it has multiple subgraphs. If yes, you can check whether the operations that are not supported by the DPU are within the scope of supported models. You can find the operations supported by the Vitis AI Library in Vitis-AI/tools/Vitis-AI-Library/cpu_task/ops.
    Note: If the operation is not in the supported list in cpu_task, then you cannot use the graph_runner directly. You may encounter an error when you compile the model. You must first solve it, then add the operation under cpu_task.
  4. Create the model_test.cpp source file. The main flow is shown in the following figure. See Vitis-AI/demo/Vitis-AI-Library/samples/graph_runner/platenum_graph_runner/platenum_graph_runner.cpp for a complete code example.

  5. Create a build.sh file as shown below, or copy one from the Vitis AI library demo and modify it.
    result=0 && pkg-config --list-all | grep opencv4 && result=1
    if [ $result -eq 1 ]; then
    	OPENCV_FLAGS=$(pkg-config --cflags --libs-only-L opencv4)
    else
    	OPENCV_FLAGS=$(pkg-config --cflags --libs-only-L opencv)
    fi
    
    CXX=${CXX:-g++}
    $CXX -std=c++17 -O2 -I. \
    	-o platenum_graph_runner \
    	platenum_graph_runner.cpp \
    	-lglog \
    	-lxir \
    	-lvart-runner \
    	-lvitis_ai_library-graph_runner \
    	${OPENCV_FLAGS} \
    	-lopencv_core \
    	-lopencv_imgcodecs \
    	-lopencv_imgproc
  6. Cross compile the program.
    sh -x build.sh
  7. Copy the executable program to the target board using the scp command.
    scp test_model root@IP_OF_BOARD:~/
  8. Install the latest VART. For more information, refer to Step 3: Installing AI Library Package.
  9. Execute the program on the target board. Before running the program, ensure that the target board has the Vitis AI Library installed, and prepare the images you want to test.
    ./model_test <model> <image>