欢迎访问我的网站,希望内容对您有用,感兴趣的可以加入免费知识星球。

PaddleDetection目标检测套件

人工智能 迷途小书童 3年前 (2020-12-10) 2866次浏览 0个评论

软硬件环境

  • ubuntu 18.04 64bit
  • nvidia 1070Ti
  • anaconda with python 3.7
  • cuda 10.1
  • cudnn 7.6
  • paddlepaddle 1.8.4
  • paddledetection 0.5

简介

引用官方的项目介绍

PaddleDetection飞桨目标检测开发套件,旨在帮助开发者更快更好地完成检测模型的组建、训练、优化及部署等全开发流程。PaddleDetection模块化地实现了多种主流目标检测算法,提供了丰富的数据增强策略、网络模块组件(如骨干网络)、损失函数等,并集成了模型压缩和跨平台高性能部署能力。经过长时间产业实践打磨,PaddleDetection已拥有顺畅、卓越的使用体验,被工业质检、遥感图像检测、无人巡检、新零售、互联网、科研等十多个行业的开发者广泛应用。

总结成一句话就是非常牛逼!

再来看看套件结构概览

Architectures Backbones Components Data Augmentation
  • Two-Stage Detection
    • Faster RCNN
    • FPN
    • Cascade-RCNN
    • Libra RCNN
    • Hybrid Task RCNN
    • PSS-Det RCNN
  • One-Stage Detection
    • RetinaNet
    • YOLOv3
    • YOLOv4
    • PP-YOLO
    • SSD
  • Anchor Free
    • CornerNet-Squeeze
    • FCOS
    • TTFNet
  • Instance Segmentation
    • Mask RCNN
    • SOLOv2
  • Face-Detction
    • FaceBoxes
    • BlazeFace
    • BlazeFace-NAS
  • ResNet(&vd)
  • ResNeXt(&vd)
  • SENet
  • Res2Net
  • HRNet
  • Hourglass
  • CBNet
  • GCNet
  • DarkNet
  • CSPDarkNet
  • VGG
  • MobileNetv1/v3
  • GhostNet
  • Efficientnet
  • Common
    • Sync-BN
    • Group Norm
    • DCNv2
    • Non-local
  • FPN
    • BiFPN
    • BFP
    • HRFPN
    • ACFPN
  • Loss
    • Smooth-L1
    • GIoU/DIoU/CIoU
    • IoUAware
  • Post-processing
    • SoftNMS
    • MatrixNMS
  • Speed
    • FP16 training
    • Multi-machine training
  • Resize
  • Flipping
  • Expand
  • Crop
  • Color Distort
  • Random Erasing
  • Mixup
  • Cutmix
  • Grid Mask
  • Auto Augment

眼睛都看花了,支持的也太xx全面了。除了功能,再来看看性能

各模型结构和骨干网络的代表模型在 COCO 数据集上精度 mAP 和单卡 Tesla V100 上预测速度( FPS )对比图

paddledetection

图中模型均可在模型库中获取,地址是 https://github.com/PaddlePaddle/PaddleDetection#%E6%A8%A1%E5%9E%8B%E5%BA%93

安装PaddlePaddle

飞桨(PaddlePaddle)是百度研发的中国首个开源开放、技术领先、功能完备的产业级深度学习平台,集深度学习核心训练和推理框架、基础模型库、端到端开发套件和丰富的工具组件于一体。

首先创建 python 的虚拟环境,然后安装 paddlepaddle-gpu

conda create -n ppdetection python=3.7
conda activate ppdetection
pip install paddlepaddle-gpu==1.8.4.post107 -i https://mirror.baidu.com/pypi/simple

如果需要使用到多 gpu 的话,还要安装 nvidiaNCCL 框架,它是用来进行多卡通讯的,下载地址是 https://developer.nvidia.com/nccl/nccl-download,选择匹配 CUDA 版本的下载

使用以下命令进行验证

(ppdetection) xugaoxiang@1070Ti:~/Works/github/PaddleDetection-release-0.5$ ipython
Python 3.7.9 (default, Aug 31 2020, 12:42:55)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import paddle.fluid as fluid

In [2]: fluid.install_check.run_check()
Running Verify Fluid Program ...
W1208 13:28:59.964426 13251 device_context.cc:252] Please NOTE: device: 0, CUDA Capability: 61, Driver API Version: 11.0, Runtime API Version: 10.0
W1208 13:29:00.090900 13251 device_context.cc:260] device: 0, cuDNN Version: 7.6.
Your Paddle Fluid works well on SINGLE GPU or CPU.
Your Paddle Fluid works well on MUTIPLE GPU or CPU.
Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now

In [3]: import paddle

In [4]: paddle.__version__
Out[4]: '1.8.4'

In [5]:

安装其它依赖

pip install pycocotools

安装PaddleDetection

目前最新的版本是0.5,下载后进入目录安装必要的依赖

wget https://github.com/PaddlePaddle/PaddleDetection/archive/release/0.5.zip
unzip PaddleDetection-release-0.5.zip
cd PaddleDetection-release-0.5
pip install -r requirements.txt

确认下面测试通过

(ppdetection) xugaoxiang@1070Ti:~/Works/github/PaddleDetection-release-0.5$ python ppdet/modeling/tests/test_architectures.py
ss/home/xugaoxiang/Works/github/PaddleDetection-release-0.5/ppdet/core/workspace.py:118: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working 
 isinstance(merge_dct[k], collections.Mapping)):
..........
----------------------------------------------------------------------
Ran 12 tests in 2.866s

OK (skipped=2)

使用官方提供的预训练模型预测图片,快速体验模型预测效果

# 通过use_gpu参数设置是否使用GPU
python tools/infer.py -c configs/ppyolo/ppyolo.yml -o use_gpu=true weights=https://paddlemodels.bj.bcebos.com/object_detection/ppyolo.pdparams --infer_img=demo/000000014439.jpg

程序运行结束后,会在 output 文件夹下生成一个画有预测结果的同名图像

paddledetection

paddledetection

paddledetection

模型训练

这里以 paddledetection 自带的苹果、香蕉和桔子数据集为例,官方代码中提供了下载脚本及配置文件

cd dataset/fruit

# 下载数据集,vod格式
python download_fruit.py

这个水果数据集是采用的 VOC 格式,下载完成后,目录结构是这样的

paddledetection

接下来就可以开始训练了,这里使用 YOLOv3 作为训练模型,backbonemobilenet_v1

python tools/train.py -c configs/yolov3_mobilenet_v1_fruit.yml --eval

其中 -c 指定训练配置文件,--eval 表示边训练边测试,配置文件中的参数解释可以参考 https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.5/docs/advanced_tutorials/config_doc/yolov3_mobilenet_v1.md,非常的详细

paddledetection

通过 visualdl 命令可以实时查看变化曲线

# 设置visualdl参数
python tools/train.py -c configs/yolov3_mobilenet_v1_roadsign.yml --eval -o use_gpu=true --use_vdl=True --vdl_log_dir=vdl_dir/scalar

# 打开visualdl
visualdl --logdir vdl_dir/scalar/ --host <host_IP> --port <port_num>

paddledetection

训练好的模型存放在 output/yolov3_mobilenet_v1_fruit

paddledetection

使用训练好的模型进行预测

# 使用参数--infer_dir来预测图片文件夹
python tools/infer.py -c configs/yolov3_mobilenet_v1_fruit.yml -o weights=output/yolov3_mobilenet_v1_fruit/best_model.pdmodel --infer_img=demo/orange_71.jpg --output_dir=output

paddledetection

paddledetection

参考资料

喜欢 (2)

您必须 登录 才能发表评论!