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 2 Current »

Multiple 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

image-20250114-094429.png

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:

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 [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

./snnf_model_creater ./vnn_yolov5suint8.c ./yolov5sModel/ YoloV5sDetection
newFilePath ./yolov5sModel/YoloV5sDetectionModelPostProcess.cpp
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModelPostProcess.cpp"
newFilePath ./yolov5sModel/YoloV5sDetectionModelInfo.cpp
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModelInfo.cpp"
newFilePath ./yolov5sModel/YoloV5sDetectionModel.h
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModel.h"
newFilePath ./yolov5sModel/YoloV5sDetectionModelPostProcess.h
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModelPostProcess.h"
newFilePath ./yolov5sModel/YoloV5sDetectionModel.cpp
copy and rename complete: "./yolov5sModel/YoloV5sDetectionModel.cpp"
Target file size: 8492
Model Generate Complete!

After execution, the model file used by SNNF will be generated in the output path:

yolov5sModel$ tree
.
├── YoloV5sDetectionModel.cpp
├── YoloV5sDetectionModel.h
├── YoloV5sDetectionModelInfo.cpp
├── YoloV5sDetectionModelPostProcess.cpp
└── YoloV5sDetectionModelPostProcess.h

2. Put the model files into the SNNF project

  1. 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 :

#define MODEL_NB_FILE           "resource/model/snnf_YoloV5sDetection.nb"
  1. Put the generated cpp file into the directory:nnmodels/sources/models/customized/YoloV5sDetection

    image-20250114-094857.png
  2. Put the generated header file into the directory:nnapi/include/models/customized/YoloV5sDetection

    image-20250114-094912.png
  1. Modify nnmodes/makefile_sources.mk,add files related to the YOLOV5s model to the project:

    image-20250114-094932.png

3. Add customized post-process code

Please add your post-process code here in file YoloV5sDetectionPostProcess.cpp

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

./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:

./snnf_run.sh -m
image-20250114-095053.png

  • No labels