todoMultiple models have been pre-prepared in SNNF that can run directly on the C3V platform. Please refer to the document for relevant model information:https://sunplus.atlassian.net/wiki/spaces/C3/pages/2404057089/V1.1.0+of+SNNF#Usage-of-V1.1.0
In SNNF code, model-related code is placed in the directory:nnmodels/sources/models
...
Divided into customized and official directories, the code in the official directory is the official provided example code. This includes parameter configuration information for the model, pre-processing, post-processing, and other code. If users want to add models to SNNF by themselves, they can follow the following process:
Table of Contents | ||
---|---|---|
|
The added steps are illustrated using the YoloV5s object detection model as an example.
1. Prepare model files
Please refer to the document for model conversion:NN Model Conversion
Retrieve the following two files from the folder yolov5s_uint8_nbg_unify after completing the model conversion:
vnn_yolov5suint8.c
network_binary.nb
Then use snnf_model_creater tools to convert model files. snnf_model_creater is now available for Ubuntu 20.04 and above.
View file | ||
---|---|---|
|
snnf_model_creater [source file] [target path] [model name]
[source file] vnn_model.c file exported by Acuity toolkit
[target path] target direct to generate
[model name] model name to create
Code Block |
---|
./snnf_model_creater ./vnn_yolov5suint8.c ./yolov5sModel/ YoloV5sDetection
copy and rename complete: "./yolov5sModel/YoloV5sDetectionPostProcess.h"
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModelInfo.cpp"
copy and rename complete: "./yolov5sModel/YoloV5sDetectionPostProcess.cpp"
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModel.h"
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModel.cpp"
Target file size: 8583
Model Generate Complete! |
After execution, the model file used by SNNF will be generated in the output path:
Code Block |
---|
yolov5sModel$ tree
.
├── YoloV5sDetectionModel.cpp
├── YoloV5sDetectionModel.h
├── YoloV5sDetectionModelInfo.cpp
├── YoloV5sDetectionModelPostProcess.cpp
└── YoloV5sDetectionModelPostProcess.h |
2. Put the model files into the SNNF project
Please rename the network_binary.nb to snnf_YoloV5sDetection.nb and then copy it to the directory: resource/model.
Double-check that the MODEL_NB_FILE which is defined in file YoloV5sDetectionModelInfo.cpp is configured with the same name as your network_binay.nb :
Code Block |
---|
#define MODEL_NB_FILE "resource/model/snnf_YoloV5sDetection.nb" |
Put the generated cpp file into the directory:nnmodels/sources/models/customized/YoloV5sDetection
Put the generated header file into the directory:nnapi/include/models/customized/YoloV5sDetection
Modify nnmodes/makefile_sources.mk,add files related to the YOLOV5s model to the project:
3. Add customized post-process code
Please add your post-process code here in file YoloV5sDetectionPostProcess.cpp
Code Block | ||
---|---|---|
| ||
void YoloV5sDetectionPostProcess::generate_proposals(
int i, uint8_t** output,
vector<shared_ptr<VnnDetectResult>>& probObjs,
vector<shared_ptr<VnnDetectResult>>& proposals)
{
uint8_t *feat = output[i]; /*NPU Tensor Out*/
DLOGD("tensor: %d output: %p\n", i, feat);
/* need to implement the process process */
/* parse nn result data from Tensor output[i]*/
/* save the final result to proposals */
} |
4. Compile and run
Code Block |
---|
./snnf_build.sh |
copy the release folder to C3V.
By using the command, you can see that the model has been added to the project:
Code Block |
---|
./snnf_run.sh -m |
...