Execute the Converted NN Model on C3V Linux
After converting the NN model using the NN Toolkit, the sample code for using the model will be automatically generated. The code is located in path "/Models/{model name}/wksp/ {model_name}_ {type}_nbg_unify". How to convert a model please refer to NN Model Conversion
The sample code encompasses operations associated with the NN model, along with preprocessing and postprocessing related to the NN model. We need to cross-compile this code into an application that can execute on C3V Linux. Additionally, we should utilize it along with the generated NB file.
1. Building
1.1. Linux Terminal Cross Compile
When compiling NN-related applications, it is necessary to include SDK's headers and libraries.
Example of SDK Includes Path:
INCLUDES+=-I$(NN_SDK_DIR)/include/ \
-I$(NN_SDK_DIR)/include/CL \
-I$(NN_SDK_DIR)/include/VX \
-I$(NN_SDK_DIR)/include/ovxlib \
-I$(NN_SDK_DIR)/include/jpeg
Example of SDK Link Libraries:
LIBS+=-lOpenVX -lOpenVXU -lCLC -lVSC -lGAL -ljpeg -lovxlib
This is an example makefile that just needs to be placed in wksp/ {model_name}_{type}_nbg_unify Folder. And set the relevant VIVIANTE_ SDK_ DIR and TOOLCHAIN can complete the compilation of the app:
#V1.0.1
BIN=yolov8s-sample
# 1.cross compile
# NN_SDK_DIR=Path to NN SDK directory
# TOOLCHAIN=Path to toolchain directory
# 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$(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
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 *~
1.2. NN IDE Cross Compile
Environment Preparations
C3V toolchain
toolchain\crossgcc\gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
C3V OVXLIB files
Import Project
select File->import:
select "General->Existing Projects into Workspace":
Browse and select the project root directory, which is Models/{your_model_name}/wksp/{model_name}_{type}_nbg_unify.
select the checkbox of the project and the checkbox of "copy project into workspace". Then press "Finish" to import the project.
Setting
This step sets the cross-compiler as the C3V toolchain and the library search path as the C3V OVXLIB folder. In the IDE main window, select "Project->Properties". Select "Tool Chain Editor" in the pop-up window. In "Current toolchain", select "Cross Gcc with openVX":
Choose "Settings" and select "Cross Settings", please configure the Prefix and Path of the C3V toolchain. configure the C3V OVXLIB search path. Then press "OK".
Build
Right-click on the model project in the Project Explorer pane, and select Build Project. The build results will appear in the Console pane.
After building success, the binary file is in the folder "Project/Debug/"
2. Running on the C3V Linux
Copy the application into C3V Linux and running:
The result is like this: