How to Use YOLOV8 Pose on C3V

This document will provide a detailed description of:

How to convert the YOLOV8 ONNX model into a model for use on the C3V platform

Write sample code for object pose based on YOLOV8

Execute object pose program and obtain recognition results in the C3V Linux environment

The tool versions involved in the current document are as follows:

NPU Kernel Driver

v6.4.15.9

v6.4.18.5

Acuity Toolkit

6.21.1

6.30.7

ViviantelIDE

5.8.2

5.10.1

1. Model Conversation

Before the conversion, it is necessary to first set up the environment for model conversion. Please refer to the following document to prepare the environment:NN Model Conversion

1.1. Project Preparation

  1. Create Model folder

Create a folder yolov8s-pose in path ~/c3v/Models. Please ensure the folder name is the same as the ONNX file name.

~/c3v/Models$ mkdir yolov8s-pose && cd yolov8s-pose
  1. Copy the ONNX file and input.jpg which resolution is 640x640 to the folder yolov8s. These two files will be used as input files during model conversion.

~/c3v/Models$ cp yolov8s-pose.onnx yolov8s-pose/ ~/c3v/Models$ cp input.jpg yolov8s-pose/
  1. Create a dataset.txt file, the content of dataset.txt is the input.jpg file name.

./input.jpg
  1. Create inputs_outputs.txt file and get the information from yolov8s-pose .onnx via netron tool/webpage. Here is the onnx file: .

image-20241105-061416.png

Select the three operators within the red box as the output. write --input-size-list and --outputs informations to inputs_outputs.txt:

After completing the above steps, there will be the following files under the yolov8s-pose path:

image-20241105-061818.png

1.2. Implementing

Using shell script tools to convert the model from ONNX to the NB file. There are 4 steps: import quantize inference and export. Tools are in ~/c3v/Models:

  • pegasus_import.sh

  • pegasus_quantize.sh

  • pegasus_inference.sh

  • pegasus_export_ovx.sh

Import

Execute the command in the console or terminal, and wait for it to complete. It will import and translate an NN model to NN formats.

Wait until the tool execution is complete and check there are no errors like this:

Then we will see the following four files added under the folder ~/c3v/Models/yolov8s.

Quantize

Modify the scale value(1/255=0.003921569) of the yolov8s-pose_inputmeta.yml file, which is in ~/c3v/Models/yolov8s.

Select one quantized type for your need, such as uint8 / int16 / bf16 / pcq. In this sample we use int16.

Wait until the tool execution is complete and check there are no errors like this:

Then we will see the following four files added under the folder ~/c3v/Models/yolov8s.

Inference

Inference the NN model with the quantization data type.

Wait until the tool execution is complete and check there are no errors like this:

Export

Export the quantized application for device deployment. Please modify the pegasus_export_ovx.sh for the nb file generating, and add both 3 lines marked in the red box.

Wait until the tool execution is complete and check there are no errors like this:

In the path ~/c3v/Models/yolov8s-pose/wksp, you will find a folder named yolov8s-pose_uint16_nbg_unify.

We can get the nb file and a c file for NN graph setup information.

2. YoloV8 Pose Program

2.1. Post Processing

The post-processing of the example code automatically transferred out by the tool will print the top 5. We need to increase the parsing of the results to obtain complete results of target recognition. The relevant post-processing functions are located in the file vnn_post_process.c.

We provide an example function for post-processing, which can complete the parsing of NN processing results:

  • post_proc_init

  • post_proc_process

  • post_proc_deinit

The function needs to be modified:vnn_PostProcessYolov8sPoseInt16

For detailed function implementation, please refer to the following file:

we needs to be unzipped and placed in ~/c3v/Models/yolov8s-pose/wksp/yolov8s_int16_nbg_unify Folder.

2.2. Program Compile

When compiling NN-related applications, SDK's headers and libraries must be included.

  • Example of SDK Includes Path:

Example of SDK Link Libraries:

3. Example flow of the program build and run

Unzipped and then placed them in ~/c3v/Models/yolov8s-pose/wksp/yolov8s-pose_int16_nbg_unify Folder. The brief folder of the project is like this:

3.1. build in c3v

If you want to build the project in c3v directly, please modify these contents of Makefile:

then copy the whole folder yolov8s-pose_int16_nbg_unify to the c3v Linux system. Then using make to compile the project.

After compilation, you can see the corresponding application program:yolov8s-pose-int16.

You can run the application directly on c3v:

The param1 is the network_binary.nb file that converts from the acuity toolkit.

The param2 is the image that is for detection. Please prepare the image file which format is jpg and the pixel size is 640 * 640.

The result is like this:

3.2. cross-compile in Linux

If you want to build the project in host Linux, please modify these contents of Makefile:

you need to set the right path of NN_SDK_DIR and TOOLCHAIN

NN_SDK_DIR: The path to NPU SDK

TOOLCHAIN: The cross-compile toolchain path. which format may be like this:

then using make to compile the project.

Copy the application, network_binary.nb file and related libraries into C3V Linux and run:

The param1 is the nb file that converts from the acuity toolkit.

The param2 is the image that is for detection. Please prepare the image file which format is jpg and the pixel size is 640 * 640.

The result is like this:

3.2. ImageWriter Tool

If you want to show the detection results in an image, we suggest using ImageWriter tools.

Please download and compile it in c3v:

Then you can run the imageWriter application directly on c3v:

Param1 is the image which is the same as yolov8s-pose-int16 param2. The yolov8s-pose-int16 is the application that is built in step 3.1. build in c3v.

Param2 is the file pose_results.raw which was generated after the program yolov8s-pose-int16 runs.

Param3 is the output name, which format is jpg.

The result is like this: