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.
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 *~ |
C3V toolchain
toolchain\crossgcc\gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
C3V OVXLIB files
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.
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".
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/"
Copy the application into C3V Linux and running:
./yolov5suint8 ./network_binary.nb ./input.jpg |
The result is like this:
Create Neural Network: 30ms or 30998us Verify... Verify Graph: 24ms or 24021us Start run graph [1] times... Run the 1 time: 43.17ms or 43173.60us vxProcessGraph execution time: Total 43.26ms or 43256.56us Average 43.26ms or 43256.56us --- Top5 --- 1347282: 4.716372 259282: 4.620119 266082: 4.620119 1354082: 4.620119 1577858: 4.620119 |