Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 in path ~/c3v/Models. Please ensure the folder name is the same as the ONNX file name.

...

Code Block
--outputs '/model.22/SplitSigmoid_output_10 /model.22/Mul_2_output_0'

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

...

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.

...

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_inputmeta.yml file, which is in ~/c3v/Models/yolov8s.

...

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.

...

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

...

1.3. Demo Video

This video is the demo for yolov8s-detection int16 quantize.

...

2. Object Detection 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.

...

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

View file
namevnnyolov8sDetection_u8_post_process.zip

2.2.

...

Program Compile

When compiling NN-related applications, it is necessary to include SDK's headers and libraries must be included.

  • Example of SDK Includes Path:

...

Code Block
LIBS+=-lOpenVX -lOpenVXU -lCLC -lVSC -lGAL -ljpeg -lovxlib

...

3. Example flow of the program build and run

Unzipped

View file
nameyolov8sDetection_u8_post_process.zip
and
View file
nameMakefile.zip
then placed them in ~/c3v/Models/yolov8s-detection/wksp/yolov8s_uint8_nbg_unify Folder. And set the relevant VIVIANTE_ SDK_ DIR and TOOLCHAIN can complete the compilation of the appThe 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:

Code Block
BIN=sampleAppyolov8s-detection-uint8

NN_SDK_DIR=Path to NN SDK directory
TOOLCHAIN=Path to toolchain directory

NN_SDK_INC=$(NN_SDK_DIR)/include
NN_SDK_LIB=$(# 2.build in c3v
NN_SDK_DIR)/lib

# 1.cross compile
#CROSS_COMPILE=$(TOOLCHAIN)/aarch64-none-linux-gnu-
#CC=$(CROSS_COMPILE)gcc
#CXX=$(CROSS_COMPILE)g++

# 2.build in c3v
#CC=gcc
#CXX=g++

CFLAGS=-Wall -O3

INCLUDE += -I$(NN_SDK_INC) -I$(NN_SDK_INC)/HAL -I$(NN_SDK_INC)/ovxlib -I$(NN_SDK_INC)/jpeg
LIBS += -L$(NN_SDK_LIB) -L./ -L$(STD_LOG_INC)
LIBS += -lOpenVX -lOpenVXU -lOpenVX -lCLC -lVSC -lGAL -ljpeg -lovxlib -lm
LIBS += -lNNArchPerf -lArchModelSw
LIBS += -lstdc++ -ldl -lpthread -lgcc_s

CFLAGS += $(INCLUDE) -fPIC

SRCS=${wildcard *.c}
SRCS+=${wildcard *.cpp}

OBJS=$(addsuffix .o, $(basename $(SRCS)))

.SUFFIXES: .hpp .cpp .c 

.cpp.o:
	$(CXX) $(CFLAGS) -std=c++11 -c $<

.c.o:
	$(CC) $(CFLAGS) -c $<

all: $(BIN)

$(BIN): $(OBJS)
	$(CC) $(CFLAGS) $(LFLAGS) $(OBJS) -o $@ $(LIBS) 
	rm -rf *.o

clean:
	rm -rf *.o
	rm -rf $(BIN) $(LIB)
	rm -rf *~

3. Running on the C3V Linux

Insmod to kernel

Code Block
insmod ./galcore.ko
[14358.019373] galcore f8140000.galcore: NPU get power success
[14358.019458] galcore f8140000.galcore: galcore irq number is 44
[14358.020542] galcore f8140000.galcore: NPU clock: 900000000
[14358.026015] Galcore version 6.4.15.9.700103

Copy the application and related libraries into C3V Linux and run:

Code Block
./yolov8suint8/usr
CC=gcc
CXX=g++

then copy the whole folder yolov8s_uint8_nbg_unify to the c3v Linux system. Then using make to compile the project.

Code Block
cd /sample/yolov8s_uint8_nbg_unify
make -j

After compilation, you can see the corresponding application program:yolov8s-detection-uint8.

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.

Code Block
./yolov8s-detection-uint8 ./network_binary.nb ./input.jpg

...

Code Block
/mnt/yolov8s_uint8_nbg_unify # ./yolov8s_sample-detection-uint8 ./network_binary.nb
../input.jpg
Create Neural Network: 28ms31ms or 28375us31666us
Verify...
Verify Graph: 21ms18ms or 21116us18520us
Start run graph [1] times...
Run the 1 time: 5752.55ms67ms or 5754852667.24us43us
vxProcessGraph execution time:
Total   5852.05ms79ms or 5805352792.36us95us
Average 5852.05ms79ms or 58053.36us 52792.95us
obj: L: 0 P:0.92, [(294, 264) - (209, 369)]
obj: L: 0 P:0.9392, [(0, 4244) - (200199, 599589)]
obj: L: 0 P:0.50, [(349, 169) - (179, 299)]
obj: L: 2 P:0.9133, [(309534, 279294) - (18074, 36164)]
obj: L: 0 P:0.5826, [(344539, 171264) - (17099, 301)]349)]

3.2. ImageWriter Tool

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

Please download

View file
nameimageWriter.zip
and compile it in c3v:

Code Block
cd imageWriter
make -j

Then you can run the imageWriter application directly on c3v:

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

Param2 is the file detect_results.raw which was generated after the program yolov8s-detection-uint8 runs.

Param3 is the output name, which format is jpg.

Code Block
./imageWriter ./input.jpg ./detect_results.raw ./output.jpg

The result is like this:

...

3.3. Demo Video

...