Super fast and lightweight anchor-free object detection model. Real-time on mobile devices.
⚡Super lightweight: Model file is only 1.8 mb. ⚡Super fast: 97fps(10.23ms) on mobile ARM CPU. 😎Training friendly: Much lower GPU memory cost than other models. Batch-size=80 is available on GTX1060 6G. 😎Easy to deploy: Provide C++ implementation and Android demo based on ncnn inference framework.
[2020.12.19] MNN python and cpp demos are available.
[2020.12.05] Support voc .xml format dataset! Refer to config/nanodet_custom_xml_dataset.yml.
[2020.12.01] Great thanks to nihui, now you can try NanoDet running in web browser!
|Model||Resolution||COCO mAP||Latency(ARM 4xCore)||FLOPS||Params||Model Size(ncnn bin)|
|NanoDet-g||416*416||22.9||Not Designed For ARM||4.2B||3.81M||7.7mb|
Performance is measured on Kirin 980(4xA76+4xA55) ARM CPU based on ncnn. You can test latency on your phone with ncnn_android_benchmark.
NanoDet mAP(0.5:0.95) is validated on COCO val2017 dataset with no testing time augmentation.
YOLO mAP refers from Scaled-YOLOv4: Scaling Cross Stage Partial Network.
NanoDet-g is designed for edge NPU, GPU or TPU with high parallel computing power but low memory bandwidth. It has much lower memory access cost than NanoDet-m.
NanoDet is a FCOS-style one-stage anchor-free object detection model which using ATSS for target sampling and using Generalized Focal Loss for classification and box regression. Please refer to these papers for more detail.
知乎中文介绍 | QQ交流群：908606542 (答案：炼丹)
Android demo project is in demo_android_ncnn folder. Please refer to Android demo guide.
NCNN C++ demo
First, install requirements and setup NanoDet following installation guide. Then download COCO pretrain weight from here
- Inference images
python demo/demo.py image --config CONFIG_PATH --model MODEL_PATH --path IMAGE_PATH
- Inference video
python demo/demo.py video --config CONFIG_PATH --model MODEL_PATH --path VIDEO_PATH
- Inference webcam
python demo/demo.py webcam --config CONFIG_PATH --model MODEL_PATH --camid YOUR_CAMERA_ID
- Linux or MacOS
- CUDA >= 10.0
- Python >= 3.6
- Pytorch >= 1.3
- experimental support Windows (Notice: Windows not support distributed training before pytorch1.7)
- Create a conda virtual environment and then activate it.
conda create -n nanodet python=3.8 -y conda activate nanodet
- Install pytorch
conda install pytorch torchvision cudatoolkit=11.0 -c pytorch
- Install requirements
pip install Cython termcolor numpy tensorboard pycocotools matplotlib pyaml opencv-python tqdm
- Setup NanoDet
git clone https://github.com/RangiLyu/nanodet.git cd nanodet python setup.py develop
How to Train
If your dataset annotations are pascal voc xml format, refer to config/nanodet_custom_xml_dataset.yml
Or convert your dataset annotations to MS COCO format(COCO annotation format details).
Prepare config file
Copy and modify an example yml config file in config/ folder.
Change save_path to where you want to save model.
Change num_classes in model->arch->head.
Change image path and annotation path in both data->train data->val.
Set gpu, workers and batch size in device to fit your device.
Set total_epochs, lr and lr_schedule according to your dataset and batchsize.
If you want to modify network, data augmentation or other things, please refer to Config File Detail
For single GPU, run
python tools/train.py CONFIG_PATH
For multi-GPU, NanoDet using distributed training. (Notice: Windows not support distributed training before pytorch1.7) Please run
python -m torch.distributed.launch --nproc_per_node=GPU_NUM --master_port 29501 tools/train.py CONFIG_PATH
TensorBoard logs are saved in
save_dirwhich you set in config file.
To visualize tensorboard logs, run:
cd SVAE_DIR tensorboard --logdir ./logs
How to Deploy
NanoDet provide C++ and Android demo based on ncnn library.
To convert NanoDet pytorch model to ncnn, you can choose this way: pytorch->onnx->ncnn
To export onnx model, run tools/export.py. Then using onnx-simplifier to simplify onnx structure.
Run onnx2ncnn in ncnn tools to generate ncnn .param and .bin file.
After that, using ncnnoptimize to optimize ncnn model.
If you have quentions about converting ncnn model, refer to ncnn wiki. https://github.com/Tencent/ncnn/wiki
Run NanoDet model with C++
Please refer to demo_ncnn.
Run NanoDet on Android
Please refer to android_demo.