PP-PicoDet

April 18, 2023 · View on GitHub

English | 简体中文

PP-PicoDet

News

  • Released a new series of PP-PicoDet models: (2022.03.20)
    • (1) It was used TAL/ETA Head and optimized PAN, which greatly improved the accuracy;
    • (2) Moreover optimized CPU prediction speed, and the training speed is greatly improved;
    • (3) The export model includes post-processing, and the prediction directly outputs the result, without secondary development, and the migration cost is lower.

Legacy Model

Introduction

We developed a series of lightweight models, named PP-PicoDet. Because of the excellent performance, our models are very suitable for deployment on mobile or CPU. For more details, please refer to our report on arXiv.

  • 🌟 Higher mAP: the first object detectors that surpass mAP(0.5:0.95) 30+ within 1M parameters when the input size is 416.
  • 🚀 Faster latency: 150FPS on mobile ARM CPU.
  • 😊 Deploy friendly: support PaddleLite/MNN/NCNN/OpenVINO and provide C++/Python/Android implementation.
  • 😍 Advanced algorithm: use the most advanced algorithms and offer innovation, such as ESNet, CSP-PAN, SimOTA with VFL, etc.

Benchmark

ModelInput sizemAPval
0.5:0.95
mAPval
0.5
Params
(M)
FLOPS
(G)
LatencyCPU
(ms)
LatencyLite
(ms)
WeightConfigInference Model
PicoDet-XS320*32023.536.10.700.673.9ms7.81msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-XS416*41626.239.30.701.136.1ms12.38msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-S320*32029.143.41.180.974.8ms9.56msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-S416*41632.547.61.181.656.6ms15.20msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-M320*32034.450.03.462.578.2ms17.68msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-M416*41637.553.43.464.3412.7ms28.39msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-L320*32036.152.05.804.2011.5ms25.21msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-L416*41639.455.75.807.1020.7ms42.23msmodel | logconfigw/ postprocess | w/o postprocess
PicoDet-L640*64042.659.25.8016.8162.5ms108.1msmodel | logconfigw/ postprocess | w/o postprocess
Table Notes:
  • Latency: All our models test on Intel core i7 10750H CPU with MKLDNN by 12 threads and Qualcomm Snapdragon 865(4xA77+4xA55) with 4 threads by arm8 and with FP16. In the above table, test CPU latency on Paddle-Inference and testing Mobile latency with Lite->Paddle-Lite.
  • PicoDet is trained on COCO train2017 dataset and evaluated on COCO val2017. And PicoDet used 4 GPUs for training and all checkpoints are trained with default settings and hyperparameters.
  • Benchmark test: When testing the speed benchmark, the post-processing is not included in the exported model, you need to set -o export.benchmark=True or manually modify runtime.yml.

Benchmark of Other Models

ModelInput sizemAPval
0.5:0.95
mAPval
0.5
Params
(M)
FLOPS
(G)
LatencyNCNN
(ms)
YOLOv3-Tiny416*41616.633.18.865.6225.42
YOLOv4-Tiny416*41621.740.26.066.9623.69
PP-YOLO-Tiny320*32020.6-1.080.586.75
PP-YOLO-Tiny416*41622.7-1.081.0210.48
Nanodet-M320*32020.6-0.950.728.71
Nanodet-M416*41623.5-0.951.213.35
Nanodet-M 1.5x416*41626.8-2.082.4215.83
YOLOX-Nano416*41625.8-0.911.0819.23
YOLOX-Tiny416*41632.8-5.066.4532.77
YOLOv5n640*64028.446.01.94.540.35
YOLOv5s640*64037.256.07.216.578.05

Quick Start

Requirements:
  • PaddlePaddle >= 2.2.2
Installation
Training and Evaluation
  • Training model on single-GPU:
# training on single-GPU
export CUDA_VISIBLE_DEVICES=0
python tools/train.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --eval

If the GPU is out of memory during training, reduce the batch_size in TrainReader, and reduce the base_lr in LearningRate proportionally. At the same time, the configs we published are all trained with 4 GPUs. If the number of GPUs is changed to 1, the base_lr needs to be reduced by a factor of 4.

  • Training model on multi-GPU:
# training on multi-GPU
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
python -m paddle.distributed.launch --gpus 0,1,2,3,4,5,6,7 tools/train.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --eval
  • Evaluation:
python tools/eval.py -c configs/picodet/picodet_s_320_coco_lcnet.yml \
              -o weights=https://paddledet.bj.bcebos.com/models/picodet_s_320_coco_lcnet.pdparams
  • Infer:
python tools/infer.py -c configs/picodet/picodet_s_320_coco_lcnet.yml \
              -o weights=https://paddledet.bj.bcebos.com/models/picodet_s_320_coco_lcnet.pdparams

Detail also can refer to Quick start guide.

Deployment

Export and Convert Model

1. Export model
cd PaddleDetection
python tools/export_model.py -c configs/picodet/picodet_s_320_coco_lcnet.yml \
              -o weights=https://paddledet.bj.bcebos.com/models/picodet_s_320_coco_lcnet.pdparams \
              --output_dir=output_inference
  • If no post processing is required, please specify: -o export.post_process=False (if -o has already appeared, delete -o here) or manually modify corresponding fields in runtime.yml.
  • If no NMS is required, please specify: -o export.nms=True or manually modify corresponding fields in runtime.yml. Many scenes exported to ONNX only support single input and fixed shape output, so if exporting to ONNX, it is recommended not to export NMS.
2. Convert to PaddleLite (click to expand)
  • Install Paddlelite>=2.10:
pip install paddlelite
  • Convert model:
# FP32
paddle_lite_opt --model_dir=output_inference/picodet_s_320_coco_lcnet --valid_targets=arm --optimize_out=picodet_s_320_coco_fp32
# FP16
paddle_lite_opt --model_dir=output_inference/picodet_s_320_coco_lcnet --valid_targets=arm --optimize_out=picodet_s_320_coco_fp16 --enable_fp16=true
3. Convert to ONNX (click to expand)
pip install onnx
pip install paddle2onnx==0.9.2
  • Convert model:
paddle2onnx --model_dir output_inference/picodet_s_320_coco_lcnet/ \
            --model_filename model.pdmodel  \
            --params_filename model.pdiparams \
            --opset_version 11 \
            --save_file picodet_s_320_coco.onnx
  • Simplify ONNX model: use onnx-simplifier to simplify onnx model.

    • Install onnxsim >= 0.4.1:
    pip install onnxsim
    
    • simplify onnx model:
    onnxsim picodet_s_320_coco.onnx picodet_s_processed.onnx
    
  • Deploy models
ModelInput sizeONNX(w/o postprocess)Paddle Lite(fp32)Paddle Lite(fp16)
PicoDet-XS320*320( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-XS416*416( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-S320*320( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-S416*416( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-M320*320( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-M416*416( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-L320*320( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-L416*416( w/ postprocess) | ( w/o postprocess)modelmodel
PicoDet-L640*640( w/ postprocess) | ( w/o postprocess) modelmodel

Deploy

Infer EnginePythonC++Predict With Postprocess
OpenVINOPythonC++(postprocess coming soon)✔︎
Paddle Lite-C++✔︎
Android Demo-Paddle Lite✔︎
PaddleInferencePythonC++✔︎
ONNXRuntimePythonComing soon✔︎
NCNNComing soonC++
MNNComing soonC++

Android demo visualization:

Quantization

Requirements:
  • PaddlePaddle >= 2.2.2
  • PaddleSlim >= 2.2.2

Install:

pip install paddleslim==2.2.2
Quant aware

Configure the quant config and start training:

python tools/train.py -c configs/picodet/picodet_s_416_coco_lcnet.yml \
          --slim_config configs/slim/quant/picodet_s_416_lcnet_quant.yml --eval
  • Quant Aware Model ZOO:
Quant ModelInput sizemAPval
0.5:0.95
ConfigsWeightInference ModelPaddle Lite(INT8)
PicoDet-S416*41631.5config | slim configmodelw/ postprocess | w/o postprocessw/ postprocess | w/o postprocess

Unstructured Pruning

Tutorial:

Please refer this documentation for details such as requirements, training and deployment.

Application

  • Pedestrian detection: model zoo of PicoDet-S-Pedestrian please refer to PP-TinyPose

  • Mainbody detection: model zoo of PicoDet-L-Mainbody please refer to mainbody detection

FAQ

Out of memory error.

Please reduce the batch_size of TrainReader in config.

How to transfer learning.

Please reset pretrain_weights in config, which trained on coco. Such as:

pretrain_weights: https://paddledet.bj.bcebos.com/models/picodet_l_640_coco_lcnet.pdparams
The transpose operator is time-consuming on some hardware.

Please use PicoDet-LCNet model, which has fewer transpose operators.

How to count model parameters.

You can insert below code at here to count learnable parameters.

params = sum([
    p.numel() for n, p in self.model. named_parameters()
    if all([x not in n for x in ['_mean', '_variance']])
]) # exclude BatchNorm running status
print('params: ', params)

Cite PP-PicoDet

If you use PicoDet in your research, please cite our work by using the following BibTeX entry:

@misc{yu2021pppicodet,
      title={PP-PicoDet: A Better Real-Time Object Detector on Mobile Devices},
      author={Guanghua Yu and Qinyao Chang and Wenyu Lv and Chang Xu and Cheng Cui and Wei Ji and Qingqing Dang and Kaipeng Deng and Guanzhong Wang and Yuning Du and Baohua Lai and Qiwen Liu and Xiaoguang Hu and Dianhai Yu and Yanjun Ma},
      year={2021},
      eprint={2111.00902},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}