...
The tool versions involved in the current document are as follows:
VIP9000 NPU Kernel Driver | v6.4.15.9 |
Acuity Toolkit | 6.21.1 |
ViviantelIDE | 5.8.2 |
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 conversionModel Conversion
1.1. Project Preparation
Create Model folder
Create a folder yolov5s in path ~/c3v/Models. Please make sure the folder name is as same as the ONNX file name.
...
Create inputs_outputs.txt file and get the information from yolov5s.onnx via netron tool/webpage. Here is the onnx file:
.View file name yolov5s_onnx.zip
...
Select the three operators within the red box as the output. write --input-size-list and --outputs informations to inputs_outputs.txt:
Code Block | ||
---|---|---|
| ||
--outputs 'onnx::Sigmoid_375 onnx::Sigmoid_419 onnx::Sigmoid_462/model.24/Transpose_output_0 /model.24/Transpose_1_output_0 /model.24/Transpose_2_output_0' |
After completing the above steps, there will be the following files under the yolov5s 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 ACUITY NN formats.
Code Block | ||
---|---|---|
| ||
./pegasus_import.sh yolov5s |
...
Then we will see the following four files added under the folder ~/c3v/Models/yolov5s.
...
Quantize
Modify the scale value(1/255=0.003921569) of the yolov5s_inputmeta.yml file, which is in ~/c3v/Models/yolov5s.
...
Then we will see the following four files added under the folder ~/c3v/Models/yolov5s.
...
Inference
Inference the ACUITY 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.
...
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 | ||
---|---|---|
|
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 |
---|
INCLUDES+=-I$(VIVANTENN_SDK_DIR)/include/ \ -I$(VIVANTENN_SDK_DIR)/include/CL \ -I$(VIVANTENN_SDK_DIR)/include/VX \ -I$(VIVANTENN_SDK_DIR)/include/ovxlib \ -I$(VIVANTENN_SDK_DIR)/include/jpeg |
Example of SDK Link Libraries:
...
This is an example Makefile that just needs to be placed in ~/c3v/Models/yolov5s/wksp/yolov5s_uint8_nbg_unify Folder. And set the relevant VIVIANTE_ SDK_ DIR and TOOLCHAIN can complete the compilation of the app:
Code Block |
---|
BIN=sampleApp VIVANTE#V1.0.1 BIN=sample # 1.cross compile # NN_SDK_DIR=Path to VIVANTENN SDK directory # TOOLCHAIN=Path to toolchain directory VIVANTE_SDK_INC=$(VIVANTE_SDK_DIR)/include VIVANTE_SDK_LIB=$(VIVANTE_SDK_DIR)/lib # CROSS_COMPILE=$(TOOLCHAIN)/aarch64-none-linux-gnu- # CC=$(CROSS_COMPILE)gcc # CXX=$(CROSS_COMPILE)g++ # 2.build in c3v # NN_SDK_DIR=/usr # CC=gcc # CXX=g++ NN_SDK_INC=$(NN_SDK_DIR)/include NN_SDK_LIB=$(NN_SDK_DIR)/lib CFLAGS=-Wall -O3 INCLUDE += -I$(VIVANTENN_SDK_INC) -I$(VIVANTENN_SDK_INC)/HAL -I$(VIVANTENN_SDK_INC)/ovxlib -I$(NN_SDK_INC)/jpeg LIBS += -L$(VIVANTENN_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 CFLAGS += -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable 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 |
...