Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
Jewel 346542255e | 2 years ago | |
---|---|---|
.. | ||
python | 2 years ago | |
CMakeLists.txt | 2 years ago | |
README.md | 2 years ago | |
main.cpp | 2 years ago | |
picodet_mnn.cpp | 2 years ago | |
picodet_mnn.hpp | 2 years ago |
This fold provides PicoDet 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.
Create picodet_m_416_coco.onnx
modelName=picodet_m_416_coco
# export model
python tools/export_model.py \
-c configs/picodet/${modelName}.yml \
-o weights=${modelName}.pdparams \
--output_dir=inference_model
# convert to onnx
paddle2onnx --model_dir inference_model/${modelName} \
--model_filename model.pdmodel \
--params_filename model.pdiparams \
--opset_version 11 \
--save_file ${modelName}.onnx
# onnxsim
python -m onnxsim ${modelName}.onnx ${modelName}_processed.onnx
Convert model
python -m MNN.tools.mnnconvert -f ONNX --modelFile picodet-416.onnx --MNNModel picodet-416.mnn
Here are converted model download link.
The python code demo_mnn.py can run directly and independently without main PicoDet repo.
PicoDetONNX
and PicoDetTorch
are two classes used to check the similarity of MNN inference results
with ONNX model and Pytorch model. They can be remove with no side effects.
For C++ code, replace libMNN.so
under ./mnn/lib with the one you just compiled, modify OpenCV path and MNN 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
demo_mnn.py
provide an inference class PicoDetMNN
that combines preprocess, post process, visualization.
Besides it can be used in command line with the form:
demo_mnn.py [-h] [--model_path MODEL_PATH] [--cfg_path CFG_PATH]
[--img_fold IMG_FOLD] [--result_fold RESULT_FOLD]
[--input_shape INPUT_SHAPE INPUT_SHAPE]
[--backend {MNN,ONNX,torch}]
For example:
# run MNN 416 model
python ./demo_mnn.py --model_path ../model/picodet-416.mnn --img_fold ../imgs --result_fold ../results
# run MNN 320 model
python ./demo_mnn.py --model_path ../model/picodet-320.mnn --input_shape 320 320 --backend MNN
# run onnx model
python ./demo_mnn.py --model_path ../model/sim.onnx --backend ONNX
C++ inference interface is same with NCNN code, to detect images in a fold, run:
./picodet-mnn "1" "../imgs/test.jpg"
For speed benchmark
./picodet-mnn "3" "0"
PaddleDetection
Python Jupyter Notebook Markdown C++ Java other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》