引用官方的項目介紹
PaddleDetection飛槳目標檢測開發套件,旨在幫助開發者更快更好地完成檢測模型的組建、訓練、優化及部署等全開發流程。PaddleDetection模塊化地實現了多種主流目標檢測算法,提供了豐富的數據增強策略、網絡模塊組件(如骨幹網絡)、損失函數等,併集成了模型壓縮和跨平臺高性能部署能力。經過長時間產業實踐打磨,PaddleDetection已擁有順暢、卓越的使用體驗,被工業質檢、遙感圖像檢測、無人巡檢、新零售、網際網路、科研等十多個行業的開發者廣泛應用。
總結成一句話就是非常牛逼!
再來看看套件結構概覽
Architectures Backbones Components Data AugmentationTwo-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
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
Loss
Smooth-L1
GIoU/DIoU/CIoU
IoUAware
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#模型庫
安裝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的話,還要安裝nvidia的NCCL框架,它是用來進行多卡通訊的,下載地址是 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文件夾下生成一個畫有預測結果的同名圖像
paddledetectionpaddledetectionpaddledetection模型訓練這裡以paddledetection自帶的蘋果、香蕉和桔子數據集為例,官方代碼中提供了下載腳本及配置文件
cd dataset/fruit
# 下載數據集,vod格式
python download_fruit.py這個水果數據集是採用的VOC格式,下載完成後,目錄結構是這樣的
paddledetection接下來就可以開始訓練了,這裡使用YOLOv3作為訓練模型,backbone是mobilenet_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
paddledetectionpaddledetection參考資料https://xugaoxiang.com/2019/12/08/anaconda/https://xugaoxiang.com/2020/09/24/ubuntu-nvidia-driver/https://xugaoxiang.com/2019/12/13/ubuntu-cuda/https://github.com/PaddlePaddle/PaddleDetectionhttps://www.paddlepaddle.org.cn/install/quick