This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
products:sbc:vim3:npu:npu-app [2023/07/05 06:30] louis |
products:sbc:vim3:npu:npu-app [2024/03/12 05:26] (current) louis |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ~~tag> VIM3 VIM3L Amlogic NPU OpenCV~~ | ||
| + | |||
| ====== Application Source Code ====== | ====== Application Source Code ====== | ||
| - | + | Guide to compiling the NPU application on the VIM3/3L. | |
| - | ===== Introduction ===== | + | |
| - | + | ||
| - | This document mainly describes how to compile executable files from application | + | |
| - | + | ||
| - | <WRAP important > | + | |
| - | Only support local compile | + | |
| - | Only support OpenCV4 | + | |
| - | </ | + | |
| ===== Install OpenCV4 ===== | ===== Install OpenCV4 ===== | ||
| + | Install the necessary library packages to build the OpenCV4 application. | ||
| ```shell | ```shell | ||
| $ sudo apt update | $ sudo apt update | ||
| Line 18: | Line 12: | ||
| ===== Get Source Code ===== | ===== Get Source Code ===== | ||
| + | Get the source code: [[gh> | ||
| ```shell | ```shell | ||
| - | $ mkdir{workspace} && cd {workspace} | ||
| $ git clone https:// | $ git clone https:// | ||
| ``` | ``` | ||
| ===== Source Description ===== | ===== Source Description ===== | ||
| + | ==== Base directory ==== | ||
| + | Base directory of the cloned repository. | ||
| + | ```shell | ||
| + | $ cd aml_npu_app | ||
| + | $ ls | ||
| + | DDK_6.3.2 | ||
| + | ``` | ||
| + | ^ File ^ Description ^ | ||
| + | | DDK_xx | Library source code, xx is the version code | | ||
| + | | detect_library | Application layer source code. the detect_library/ | ||
| + | | NN_SLT | Separate source code directory for DnCnn model (no longer maintained). | | ||
| + | | LICENSE | LICENSE file. | | ||
| + | | | ||
| + | ==== Detect library ==== | ||
| + | Directory with various model specific application code. | ||
| + | ```shell | ||
| + | $ cd aml_npu_app/ | ||
| + | $ ls | ||
| + | densenet_ctc_demo_picture | ||
| + | yolo_demo_x11_mipi | ||
| + | ``` | ||
| - | ==== Directory structure description | + | ^ File ^ Description ^ |
| + | | **model_code** | ||
| + | | **source_code** | Provide interfaces for demo to call model_code. | | ||
| + | | **Other folders** | Application source code | | ||
| + | |||
| + | ==== Model code ==== | ||
| + | Directory containing all the detection library code. | ||
| ```shell | ```shell | ||
| - | $ cd {workspace}/ | + | $ cd aml_npu_app/ |
| $ ls | $ ls | ||
| - | DDK_6.3.2 | + | densenet_ctc |
| + | detect_yolov8n | ||
| ``` | ``` | ||
| - | * **DDK_xxx** - Different versions of library source code | + | Except |
| - | * **detect_library** - Application layer source code. detect_library/ | + | |
| - | * **NN_SLT** - Separate source code directory | + | |
| - | * **LICENSE** - LICENSE file | + | |
| - | ==== Library | + | ^ File ^ Description |
| + | | **densenet_ctc** | Character recognition, | ||
| + | | **detect_retinaface** | Detect faces and the keypoints of faces. | | ||
| + | | **detect_yoloface** | yoloface model, used to detect faces without keypoints. | | ||
| + | | **detect_yolo_v2** | yolov2 model, for object detection. | | ||
| + | | **detect_yolo_v3** | yolov3 model, for object detection. | | ||
| + | | **detect_yolo_v3_tiny** | yolov3-tiny model, for object detection. | | ||
| + | | **detect_yolo_v4** | yolov4 model, used to detect faces. | | ||
| + | | **detect_yolo_v7_tiny** | yolov7_tiny model, for object detection. | | ||
| + | | **detect_yolov8n** | yolov8n model, for object detection. The latest yolo model. | | ||
| + | | **facenet** | Deprecated - No longer in use. | | ||
| + | |||
| + | |||
| + | Take '' | ||
| ```shell | ```shell | ||
| - | $ cd {workspace}/ | + | $ cd aml_npu_app/ |
| $ ls | $ ls | ||
| - | densenet_ctc_demo_picture | + | build_vx.sh |
| - | yolo_demo_x11_usb | + | |
| ``` | ``` | ||
| - | | + | ^ File ^ Description ^ |
| - | * **source_code** - Provide interfaces for demo to call model_code. | + | | **build_vx.sh** | Compile script. | |
| - | * **Other folders** - Load input and visualize | + | | **include** | The corresponding header files and all definitions will be placed in this directory. | |
| + | | **Makefile** | Makefile file. | | ||
| + | | **makefile.linux** | Make environment configuration file. | | ||
| + | | **vnn_yolov3.c** | SDK The converted model processing file is mainly used to interface with the nb file. | | ||
| + | | **yolo_v3.c** | Specify the called nb file, and define all the interfaces of the model call. | | ||
| + | | **yolov3_process.c** | Mainly defines the pre-processing | ||
| - | Enter the directory of the library | + | ==== Source code ==== |
| + | Directory containing | ||
| ```shell | ```shell | ||
| - | $ cd {workspace}/ | + | $ cd aml_npu_app/ |
| $ ls | $ ls | ||
| - | densenet_ctc | + | build_vx.sh |
| ``` | ``` | ||
| - | Except | + | ^ File ^ Description ^ |
| + | | **build_vx.sh** | Compile script. | | ||
| + | | **detect.c** | Provide interface | ||
| + | | **detect_log.c** | About log level. | | ||
| + | | **include** | The corresponding header files and all definitions | ||
| + | | **Makefile** | Makefile file. | | ||
| + | | **makefile.linux** | Make environment configuration file. | | ||
| - | * **densenet_ctc** - Character recognition, | ||
| - | * **detect_retinaface** - Detect faces and the keypoints of faces. | ||
| - | * **detect_yoloface** - yoloface model, used to detect faces without keypoint. | ||
| - | * **detect_yolo_v2** - yolov2 model, for object detection. | ||
| - | * **detect_yolo_v3** - yolov3 model, for object detection. | ||
| - | * **detect_yolo_v3_tiny** - yolov3-tiny model, for object detection. | ||
| - | * **detect_yolo_v4** - yolov4 model, used to detect faces. | ||
| - | * **detect_yolo_v7_tiny** - yolov7_tiny model, for object detection. | ||
| - | * **detect_yolov8n** - yolov8n model, for object detection. The latest yolo model. | ||
| - | * **facenet** - Has been deprecated. | ||
| - | Take '' | + | Enter the directory of the '' |
| ```shell | ```shell | ||
| - | $ cd {workspace}/ | + | $ cd aml_npu_app/ |
| $ ls | $ ls | ||
| - | build_vx.sh | + | build_vx.sh |
| ``` | ``` | ||
| - | Main content description: | + | ^ File ^ Description ^ |
| + | | **build_vx.sh** | Compile script. | | ||
| + | | **main.cpp** | Main function. | | ||
| + | | **detect.h**, | ||
| + | | **makefile.linux** | Make environment configuration file. | | ||
| + | | **makefile.target_name** | The name of the compiled executable. | | ||
| - | * **build_vx.sh** - Compile | + | ===== Compile the application===== |
| - | * **include** - The corresponding header files and all definitions will be placed in this directory. | + | |
| - | * **Makefile** - Makefile file. | + | |
| - | * **makefile.linux** - Make environment configuration file. | + | |
| - | * **vnn_yolov3.c** - SDK The converted model processing file is mainly used to interface with the nb file. | + | |
| - | * **yolo_v3.c** - Specify the called nb file, and define all the interfaces of the model call. | + | |
| - | * **yolov3_process.c** - Mainly defines the pre-processing and post-processing of the model. | + | |
| - | Enter the directory of the library source_code. | + | 1. Compile |
| ```shell | ```shell | ||
| - | $ cd {workspace}/ | + | $ cd aml_npu_app/ |
| $ ls | $ ls | ||
| - | build_vx.sh | + | build_vx.sh |
| + | $ bash build_vx.sh | ||
| + | $ ls | ||
| + | bin_r build_vx.sh | ||
| ``` | ``` | ||
| - | Main content description: | + | 2. The compiled library '' |
| - | * **build_vx.sh** - Compile script. | + | ```shell |
| - | * **detect.c** - Provide interface for detect and call model_code. | + | $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: |
| - | * **detect_log.c** - About log level. | + | ``` |
| - | * **include** - The corresponding header files and all definitions will be placed in this directory. | + | |
| - | * **Makefile** - Makefile file. | + | |
| - | * **makefile.linux** - Make environment configuration file. | + | |
| + | 3. You will also need to build the contents of the '' | ||
| + | ```shell | ||
| + | $ cd aml_npu_app/ | ||
| + | $ ls | ||
| + | build_vx.sh | ||
| + | $ bash build_vx.sh | ||
| + | $ ls | ||
| + | bin_r build_vx.sh | ||
| + | ``` | ||
| + | 4. The compiled library '' | ||
| + | |||
| + | ```shell | ||
| + | $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: | ||
| + | ``` | ||
| + | |||
| + | 5. Now, Build the example application. | ||
| + | ```shell | ||
| + | $ cd aml_npu_app/ | ||
| + | $ ls | ||
| + | build_vx.sh | ||
| + | $ bash build_vx.sh | ||
| + | $ ls | ||
| + | bin_r_cv4 | ||
| + | ``` | ||
| + | |||
| + | <WRAP important > | ||
| + | If you use kernel are using version 5.15 or above, please remove the red lines in '' | ||
| + | </ | ||
| + | |||
| + | ```diff | ||
| + | LIBS += -L$(VIVANTE_SDK_LIB) -lOpenVX -lOpenVXU -lGAL -lovxlib -lArchModelSw -lNNArchPerf | ||
| + | |||
| + | LIBS += -L../ | ||
| + | |||
| + | -#LIBS +=-L$(LIB_DIR) -lstdc++ | ||
| + | -LIBS += -lvpcodec -lamcodec -lamadec -lamvdec -lamavutils -lrt -lpthread -lge2d -lion | ||
| + | |||
| + | ############################################################################# | ||
| + | # Macros. | ||
| + | PROGRAM = 1 | ||
| + | CUR_SOURCE = ${wildcard *.c} | ||
| + | ############################################################################# | ||
| + | ``` | ||
| + | |||
| + | 6. Create a folder named '' | ||
| + | ```shell | ||
| + | $ cd bin_r_cv4 | ||
| + | $ mkdir nn_data | ||
| + | $ cp -r xx/ | ||
| + | $ ls | ||
| + | detect_demo_x11_usb | ||
| + | ``` | ||
| + | ===== Run the application ===== | ||
| + | |||
| + | Now you can run inference on captured video data using the model. | ||
| + | ```shell | ||
| + | $ ./ | ||
| + | ``` | ||
| + | ==== Application setup parameters ==== | ||
| + | === Parameter to select the detection model === | ||
| + | |||
| + | The parameter '' | ||
| + | |||
| + | ^ Index ^ File ^ | ||
| + | | **0** | detect_yoloface | | ||
| + | | **1** | detect_yolo_v2 | | ||
| + | | **2** | detect_yolo_v3 | | ||
| + | | **3** | detect_yolo_v3_tiny | | ||
| + | | **4** | detect_yolo_v4 | | ||
| + | | **13** | detect_yolo_v7_tiny | | ||
| + | | **14** | detect_yolov8n | | ||
| + | | **15** | densenet_ctc | | ||
| + | | **16** | detect_retinaface | | ||
| + | |||
| + | |||
| + | For the above example, we used the serial number '' | ||
| + | |||
| + | === Parameter to set the input as picture === | ||
| + | |||
| + | If you use the model that takes input as a picture, change '' | ||
| + | ```shell | ||
| + | $ ./ | ||
| + | ``` | ||