This fold provides NanoDet inference code using Alibaba's MNN framework. Most of the implements in this fold are same as demo_ncnn.
Just run:
pip install MNN
Please follow the official document to build MNN engine.
-
Export ONNX model
python tools/export_onnx.py --cfg_path ${CONFIG_PATH} --model_path ${PYTORCH_MODEL_PATH}
-
Convert to MNN
python -m MNN.tools.mnnconvert -f ONNX --modelFile sim.onnx --MNNModel nanodet.mnn
It should be note that the input size does not have to be fixed, it can be any integer multiple of strides,
since NanoDet is anchor free. We can adapt the shape of dummy_input
in ./tools/export_onnx.py to get ONNX and MNN models
with different input sizes.
Here are converted model Download Link.
For C++ code, replace libMNN.so
under ./mnn/lib with the one you just compiled, modify OpenCV path at CMake file,
and run
mkdir build && cd build
cmake ..
make
Note that a flag at main.cpp
is used to control whether to show the detection result or save it into a fold.
#define __SAVE_RESULT__ // if defined save drawed results to ../results, else show it in windows
The multi-backend python demo is still working in progress.
C++ inference interface is same with NCNN code, to detect images in a fold, run:
./nanodet-mnn "1" "../imgs/*.jpg"
For speed benchmark
./nanodet-mnn "3" "0"
If you want to use custom model, please make sure the hyperparameters
in nanodet_mnn.h
are the same with your training config file.
int input_size[2] = {416, 416}; // input height and width
int num_class = 80; // number of classes. 80 for COCO
int reg_max = 7; // `reg_max` set in the training config. Default: 7.
std::vector<int> strides = { 8, 16, 32, 64 }; // strides of the multi-level feature.