yuv_yolov5_app

 

Table of contents


 

Introduction


This explanation assumes that the i-PRO camera application development environment has been completed.
If you are not ready to build the development environment, please refer to here to complete it.

Also, in this tutorial, the SDK installation directory is described as ${SDK_DIR}.

Operation overview


yuv_yolov5_app is a sample application that draws object names and frames on the model on the camera.

 

External libraries required for operation


To build with Python, need below:

numpy

OpenCV

The use of external libraries will be explained later.

 

Directory path of the sample app


The C/C++ source code is stored below.

${SDK_DIR}/src/adamapp/yuv_yolov5_app

The Python source code is stored below.

${SDK_DIR}/src/adamapp-py/yuv_yolov5_app

 

Use of AI model conversion tool


Before building the sample app, you need to use the AI model conversion tool.

Get the AI model conversion tool from below and build the environment.

AI model convert tool - Technology Partner FAQ (En) - Confluence (atlassian.net)

It may take several days from the time you make an inquiry to the time it is provided.

 After building the environment, refer to the following and convert the yolov5 sample model.

AI model convert tool: ONNX(PyTorch) - Technology Partner FAQ (En) - Confluence (atlassian.net)

Here, the model converted file is explained as "yolov5_cavalry.bin".

 

How to build the sample app (C/C++)


This article describes how to build it as AdamApp.
If you want to build it as Container AdamApp for Azure IoT Edge, see below.

Development tutorial (Container AdamApp for Azure IoT Edge) - Technology Partner FAQ (En) - Confluence (atlassian.net)

If you want to build it as Container AdamApp, see below.

Development tutorial (Container AdamApp) - Technology Partner FAQ (En) - Confluence

Load the build environment settings file in the SDK installation directory.

$ cd ${SDK_DIR} $ source setup_env.sh ipro-ambaCV2X

 

Next, place the model-converted yolov5_cavalry.bin file in the sample app directory with the following configuration.

[For ambaCV2X app]
${SDK_DIR}/src/adamapp/yuv_yolov5_app/data_CV2X/cnn/yolov5_cavalry.bin
[For ambaCV5X app]
${SDK_DIR}/src/adamapp/yuv_yolov5_app/data_CV5X/cnn/yolov5_cavalry.bin

make.

$ cd src/adamapp/yuv_yolov5_app $ make

It is successful if the .ext file is created in ${SDK_DIR}/src/adamapp/yuv_yolov5_app.

 

Install it on the camera (eg, you can install from the green frame in the image below). Select the created .ext file and install it.
Open the app screen (red frame button in the image below).

 

After installation, wait until the AI model has finished loading on the management log screen. This may take several minutes.

20240412-132701-e.png

If the image of the camera is displayed, it is successful.

 

How to build the sample app (Python)


Place the model-converted yolov5_cavalry.bin file in the sample app directory with the following configuration.

[For ambaCV2X app]
${SDK_DIR}/src/adamapp-py/yuv_yolov5_app/data_CV2X/cnn/yolov5_cavalry.bin
[For ambaCV5X app]
${SDK_DIR}/src/adamapp-py/yuv_yolov5_app/data_CV5X/cnn/yolov5_cavalry.bin

See here for building with Python.

 

After installation, wait until the AI model has finished loading on the management log screen. This may take several minutes.

If the image of the camera is displayed, it is successful.

 

How to use the sample app


Take a picture of some model with your camera. In the example below, you can see that the model (hand and fingers) is surrounded by a frame and the object name (person) is displayed.

 

Appendix


How to change preferences

This application has some preferneces which a user is able to change.
When changing some preferneces, push "AppPrefs" button in "ADAM OPERATION UI" html page.

Resoultion:
Resolution to get YUV images. Specfify HD(1280x720) or FHD(1920x1080).
However, by the ability of the camera, it may not work with the specified value.

Frame rate:
Frame rate to get YUV images. Specify 1 or more.
However, by the ability of the camera, it may not work with the specified value.

 

How to change AI model

  1. Please replace
    data_CV2X/cnn/*.bin
    and
    data_CV5X/cnn/*.bin
    with your model.

  2. Please change the following part of main.cpp according to the model specifications.

    #define OUTSIZE_HEIGHT <Model input height>
    #define OUTSIZE_WIDTH <Model input width>
    #define NETNAME <Model file name>
    #define LAYERNAMEIN <Model input layer>
    #define LAYERNAMEOUT_CONV1037 <Layer name of feature map (stride 32)>
    #define LAYERNAMEOUT_CONV1017 <Layer name of feature map (stride 16)>
    #define LAYERNAMEOUT_CONV997 <Layer name of feature map (stride 8)>
    #define TOTAL_CLS <Number of model classes>

    char const *names (object_name_list in pymain.py)
    Please change it according to the model specifications.
    const float anchors (anchors_list in pymain.py)
    The value of anchors in the URL below is used.
    https://github.com/ultralytics/yolov5/blob/master/models/yolov5s.yaml
    The values may vary depending on the model, so please check the model specifications.


・About the layer name set in LAYERNAMEOUT

yuv_yolov5_app (and yuv_yolo_app) are created on the premise that the feature map is the output of the AI model.
Example: yolov5s with input resolution 640x640
The last conv layer (3) is the layer that outputs the feature map. c: 3×(5+number of classes). In this example, c=255, so the number of classes is 80. h, w: Grid number of feature map. It is the input resolution divided by stride.

Therefore, the settings for LAYERNAMEOUT are as follows.
#define LAYERNAMEOUT_CONV1037 "418" // stride 32
#define LAYERNAMEOUT_CONV1017 "372" // stride 16
#define LAYERNAMEOUT_CONV997 "326" // stride 8

 

Port in use

This application uses 8083 port for websocket communication.