Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

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:

BIN=sampleApp

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

NN_SDK_INC=$(NN_SDK_DIR)/include
NN_SDK_LIB=$(NN_SDK_DIR)/lib

CROSS_COMPILE=$(TOOLCHAIN)/aarch64-none-linux-gnu-

CC=$(CROSS_COMPILE)gcc
CXX=$(CROSS_COMPILE)g++

CFLAGS=-Wall -O3

INCLUDE += -I$(NN_SDK_INC) -I$(NN_SDK_INC)/HAL -I$(NN_SDK_INC)/ovxlib
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 *~

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

image-20240204-084410.png

Import Project

select File->import:

image-20240204-085331.png

select "General->Existing Projects into Workspace":

image-20240204-085258.png

Browse and select the project root directory, which is Models/{your_model_name}/wksp/{model_name}_{type}_nbg_unify.

image-20240204-084458.png

select the checkbox of the project and the checkbox of "copy project into workspace". Then press "Finish" to import the project.

image-20240204-084510.png

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":

image-20240204-084526.png

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".

image-20240204-084538.png

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.

image-20240204-084549.png

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:

./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
  • No labels