1 Star 0 Fork 255

xiaoqin00 / PaddleDetection

forked from PaddlePaddle / PaddleDetection 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 24.86 KB
一键复制 编辑 原始数据 按行查看 历史
wangguanzhong 提交于 2023-02-14 17:31 . update 2.6 doc (#7758)

简体中文 | English

PP-PicoDet

最新动态

  • 发布PicoDet-NPU模型,支持模型全量化部署。详情请参考PicoDet全量化示例 (2022.08.10)

  • 发布全新系列PP-PicoDet模型:(2022.03.20)

    • (1)引入TAL及ETA Head,优化PAN等结构,精度提升2个点以上;
    • (2)优化CPU端预测速度,同时训练速度提升一倍;
    • (3)导出模型将后处理包含在网络中,预测直接输出box结果,无需二次开发,迁移成本更低,端到端预测速度提升10%-20%。

历史版本模型

简介

PaddleDetection中提出了全新的轻量级系列模型PP-PicoDet,在移动端具有卓越的性能,成为全新SOTA轻量级模型。详细的技术细节可以参考我们的arXiv技术报告

PP-PicoDet模型有如下特点:

  • 🌟 更高的mAP: 第一个在1M参数量之内mAP(0.5:0.95)超越30+(输入416像素时)。
  • 🚀 更快的预测速度: 网络预测在ARM CPU下可达150FPS。
  • 😊 部署友好: 支持PaddleLite/MNN/NCNN/OpenVINO等预测库,支持转出ONNX,提供了C++/Python/Android的demo。
  • 😍 先进的算法: 我们在现有SOTA算法中进行了创新, 包括:ESNet, CSP-PAN, SimOTA等等。

基线

模型 输入尺寸 mAPval
0.5:0.95
mAPval
0.5
参数量
(M)
FLOPS
(G)
预测时延CPU
(ms)
预测时延Lite
(ms)
权重下载 配置文件 导出模型
PicoDet-XS 320*320 23.5 36.1 0.70 0.67 3.9ms 7.81ms model | log config w/ 后处理 | w/o 后处理
PicoDet-XS 416*416 26.2 39.3 0.70 1.13 6.1ms 12.38ms model | log config w/ 后处理 | w/o 后处理
PicoDet-S 320*320 29.1 43.4 1.18 0.97 4.8ms 9.56ms model | log config w/ 后处理 | w/o 后处理
PicoDet-S 416*416 32.5 47.6 1.18 1.65 6.6ms 15.20ms model | log config w/ 后处理 | w/o 后处理
PicoDet-M 320*320 34.4 50.0 3.46 2.57 8.2ms 17.68ms model | log config w/ 后处理 | w/o 后处理
PicoDet-M 416*416 37.5 53.4 3.46 4.34 12.7ms 28.39ms model | log config w/ 后处理 | w/o 后处理
PicoDet-L 320*320 36.1 52.0 5.80 4.20 11.5ms 25.21ms model | log config w/ 后处理 | w/o 后处理
PicoDet-L 416*416 39.4 55.7 5.80 7.10 20.7ms 42.23ms model | log config w/ 后处理 | w/o 后处理
PicoDet-L 640*640 42.6 59.2 5.80 16.81 62.5ms 108.1ms model | log config w/ 后处理 | w/o 后处理
  • 特色模型
模型 输入尺寸 mAPval
0.5:0.95
mAPval
0.5
参数量
(M)
FLOPS
(G)
预测时延CPU
(ms)
预测时延Lite
(ms)
权重下载 配置文件
PicoDet-S-NPU 416*416 30.1 44.2 - - - - model | log config
注意事项:
  • 时延测试: 我们所有的模型都在英特尔酷睿i7 10750H的CPU 和骁龙865(4xA77+4xA55)的ARM CPU上测试(4线程,FP16预测)。上面表格中标有CPU的是使用OpenVINO测试,标有Lite的是使用Paddle Lite进行测试。
  • PicoDet在COCO train2017上训练,并且在COCO val2017上进行验证。使用4卡GPU训练,并且上表所有的预训练模型都是通过发布的默认配置训练得到。
  • Benchmark测试:测试速度benchmark性能时,导出模型后处理不包含在网络中,需要设置-o export.benchmark=True 或手动修改runtime.yml

其他模型的基线

模型 输入尺寸 mAPval
0.5:0.95
mAPval
0.5
参数量
(M)
FLOPS
(G)
预测时延NCNN
(ms)
YOLOv3-Tiny 416*416 16.6 33.1 8.86 5.62 25.42
YOLOv4-Tiny 416*416 21.7 40.2 6.06 6.96 23.69
PP-YOLO-Tiny 320*320 20.6 - 1.08 0.58 6.75
PP-YOLO-Tiny 416*416 22.7 - 1.08 1.02 10.48
Nanodet-M 320*320 20.6 - 0.95 0.72 8.71
Nanodet-M 416*416 23.5 - 0.95 1.2 13.35
Nanodet-M 1.5x 416*416 26.8 - 2.08 2.42 15.83
YOLOX-Nano 416*416 25.8 - 0.91 1.08 19.23
YOLOX-Tiny 416*416 32.8 - 5.06 6.45 32.77
YOLOv5n 640*640 28.4 46.0 1.9 4.5 40.35
YOLOv5s 640*640 37.2 56.0 7.2 16.5 78.05

快速开始

依赖包:
  • PaddlePaddle == 2.2.2
安装
训练&评估
  • 单卡GPU上训练:
# training on single-GPU
export CUDA_VISIBLE_DEVICES=0
python tools/train.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --eval

**注意:**如果训练时显存out memory,将TrainReader中batch_size调小,同时LearningRate中base_lr等比例减小。同时我们发布的config均由4卡训练得到,如果改变GPU卡数为1,那么base_lr需要减小4倍。

  • 多卡GPU上训练:
# training on multi-GPU
export CUDA_VISIBLE_DEVICES=0,1,2,3
python -m paddle.distributed.launch --gpus 0,1,2,3 tools/train.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --eval

**注意:**PicoDet所有模型均由4卡GPU训练得到,如果改变训练GPU卡数,需要按线性比例缩放学习率base_lr。

  • 评估:
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
  • 测试:
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

详情请参考快速开始文档.

部署

导出及转换模型

1. 导出模型
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
  • 如无需导出后处理,请指定:-o export.benchmark=True(如果-o已出现过,此处删掉-o)或者手动修改runtime.yml 中相应字段。
  • 如无需导出NMS,请指定:-o export.nms=False或者手动修改runtime.yml 中相应字段。 许多导出至ONNX场景只支持单输入及固定shape输出,所以如果导出至ONNX,推荐不导出NMS。
2. 转换模型至Paddle Lite (点击展开)
  • 安装Paddlelite>=2.10:
pip install paddlelite
  • 转换模型至Paddle Lite格式:
# 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. 转换模型至ONNX (点击展开)
pip install onnx
pip install paddle2onnx==0.9.2
  • 转换模型:
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
  • 简化ONNX模型: 使用onnx-simplifier库来简化ONNX模型。

    • 安装 onnxsim >= 0.4.1:
    pip install onnxsim
    • 简化ONNX模型:
    onnxsim picodet_s_320_coco.onnx picodet_s_processed.onnx
  • 部署用的模型
模型 输入尺寸 ONNX Paddle Lite(fp32) Paddle Lite(fp16)
PicoDet-XS 320*320 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-XS 416*416 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-S 320*320 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-S 416*416 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-M 320*320 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-M 416*416 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-L 320*320 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-L 416*416 ( w/ 后处理) | ( w/o 后处理) model model
PicoDet-L 640*640 ( w/ 后处理) | ( w/o 后处理) model model

部署

预测库 Python C++ 带后处理预测
OpenVINO Python C++(带后处理开发中) ✔︎
Paddle Lite - C++ ✔︎
Android Demo - Paddle Lite ✔︎
PaddleInference Python C++ ✔︎
ONNXRuntime Python Coming soon ✔︎
NCNN Coming soon C++
MNN Coming soon C++

Android demo可视化:

量化

依赖包:
  • PaddlePaddle >= 2.2.2
  • PaddleSlim >= 2.2.2

安装:

pip install paddleslim==2.2.2
量化训练

开始量化训练:

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
  • 量化训练Model ZOO:
量化模型 输入尺寸 mAPval
0.5:0.95
Configs Weight Inference Model Paddle Lite(INT8)
PicoDet-S 416*416 31.5 config | slim config model w/ 后处理 | w/o 后处理 w/ 后处理 | w/o 后处理

非结构化剪枝

教程:

训练及部署细节请参考非结构化剪枝文档

应用

  • 行人检测: PicoDet-S-Pedestrian行人检测模型请参考PP-TinyPose

  • 主体检测: PicoDet-L-Mainbody主体检测模型请参考主体检测文档

FAQ

显存爆炸(Out of memory error)

请减小配置文件中TrainReaderbatch_size

如何迁移学习

请重新设置配置文件中的pretrain_weights字段,比如利用COCO上训好的模型在自己的数据上继续训练:

pretrain_weights: https://paddledet.bj.bcebos.com/models/picodet_l_640_coco_lcnet.pdparams
`transpose`算子在某些硬件上耗时验证

请使用PicoDet-LCNet模型,transpose较少。

如何计算模型参数量。

可以将以下代码插入:trainer.py 来计算参数量。

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)

引用PP-PicoDet

如果需要在你的研究中使用PP-PicoDet,请通过一下方式引用我们的技术报告:

@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}
}
Python
1
https://gitee.com/xiaoqin00/PaddleDetection.git
git@gitee.com:xiaoqin00/PaddleDetection.git
xiaoqin00
PaddleDetection
PaddleDetection
release/2.6

搜索帮助