- PaddlePaddle 2.2
- OS 64位 *** 作系统
- Python 3(3.5.1+/3.6/3.7/3.8/3.9),64位版本
- pip/pip3(9.0.1+),64位版本
- CUDA >= 10.1
- cuDNN >= 7.6
# CUDA10.1
python -m pip install paddlepaddle-gpu==2.2.0.post101 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html
# CPU
python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
# 在您的Python解释器中确认PaddlePaddle安装成功
>>> import paddle
>>> paddle.utils.run_check()
# 确认PaddlePaddle版本
python -c "import paddle; print(paddle.__version__)"
# 克隆PaddleDetection仓库
cd
git clone https://github.com/PaddlePaddle/PaddleDetection.git
# 安装其他依赖
cd PaddleDetection
pip install -r requirements.txt
# 编译安装paddledet
python setup.py install
安装后确认测试通过:
python ppdet/modeling/tests/test_architectures.py
测试通过后会提示如下信息:
....... ---------------------------------------------------------------------- Ran 7 tests in 12.816s OK
有一说一,paddle的安装是真的方便,paddledetection也很简单,比mmlab不知道轻松到哪里去了。
二、准备数据因为我一直沿用VOC格式数据,所以稍加改动就可以做成paddle需要的样子
如果你并未组织VOC格式的数据集,那么我建议你在标注完成后使用:
YOLO5 训练自定义数据集及避坑指南_訢詡的博客-CSDN博客一、项目地址:https://github.com/ultralytics/yolov5https://github.com/ultralytics/yolov5数据集完全可以沿用VOCDevkit格式数据集二、VOCDevkit格式数据|--VOC2007|---Annotations|---ImageSets|----Layout|----Main...http://www.kaotop.com/file/tupian/20220423/xxxxxxxx1.jpg
aaa/bb/ccc/JPEGImages/xxxxxxxx2.jpg
而paddle要求的为:
aaa/bb/ccc/JPEGImages/xxxxxxxx1.jpg aaa/bb/ccc/Annotation/xxxxxxxx1.xml
aaa/bb/ccc/JPEGImages/xxxxxxxx2.jpg aaa/bb/ccc/Annotation/xxxxxxxx2.xml
按Ctrl+Hda打开替换,点击*按钮打开正则表达式
(1)将(aaa/bb/ccc/JPEGImages/([a-z0-9_-]*))替换为$1.jpg $1.xml
(2)将.xml.jpg替换为.xml
(3)将(aaa/bb/ccc/JPEGImages/([a-z0-9_-]*).jpg aaa/bb/ccc/)/JPEGImages([a-z0-9_-]*.xml)替换为$1/Annotation$2
就可以做出paddle需要的形式了。
>>cd dataset/voc/ >>tree ├── create_list.py ├── download_voc.py ├── generic_det_label_list.txt ├── generic_det_label_list_zh.txt ├── label_list.txt ├── trainval.txt ├── test.txt ├── VOCdevkit/VOC2007 │ ├── annotations │ ├── 001789.xml │ | ... │ ├── JPEGImages │ ├── 001789.jpg │ | ... │ ├── ImageSets │ | ... ├── VOCdevkit/VOC2012 │ ├── Annotations │ ├── 2011_003876.xml │ | ... │ ├── JPEGImages │ ├── 2011_003876.jpg │ | ... │ ├── ImageSets │ | ... | ...
三、配置# label_list.txt 是类别名称列表,文件名必须是 label_list.txt。若使用VOC数据集,config文件中use_default_label为true时不需要这个文件 >>cat label_list.txt aeroplane bicycle ... # trainval.txt 是训练数据集文件列表 >>cat trainval.txt VOCdevkit/VOC2007/JPEGImages/007276.jpg VOCdevkit/VOC2007/Annotations/007276.xml VOCdevkit/VOC2012/JPEGImages/2011_002612.jpg VOCdevkit/VOC2012/Annotations/2011_002612.xml ... # test.txt 是测试数据集文件列表 >>cat test.txt VOCdevkit/VOC2007/JPEGImages/000001.jpg VOCdevkit/VOC2007/Annotations/000001.xml ... # label_list.txt voc 类别名称列表 >>cat label_list.txt aeroplane bicycle ...
(1)上面的label_list.txt里面就得换成自己的分类列表
(2)打开/PaddleDetection/configs/yolov3/yolov3_darknet53_270e_voc.yml
_BASE_: [
'../datasets/voc.yml',
'../runtime.yml',
'_base_/optimizer_270e.yml',
'_base_/yolov3_darknet53.yml',
'_base_/yolov3_reader.yml',
]
snapshot_epoch: 5
weights: output/yolov3_darknet53_270e_voc/model_final
# set collate_batch to false because ground-truth info is needed
# on voc dataset and should not collate data in batch when batch size
# is larger than 1.
EvalReader:
collate_batch: false
它会依赖这5个配置文件
(3)打开/PaddleDetection/configs/yolov3/_base_/optimizer_270e.yml
epoch: 20
LearningRate:
base_lr: 0.001
schedulers:
- !PiecewiseDecay
gamma: 0.1
milestones:
- 216
- 243
- !LinearWarmup
start_factor: 0.
steps: 4000
OptimizerBuilder:
optimizer:
momentum: 0.9
type: Momentum
regularizer:
factor: 0.0005
type: L2
这里修改训练次数和初始学习率
(4)打开/PaddleDetection/configs/yolov3/_base_/yolov3_reader.yml
worker_num: 2
TrainReader:
inputs_def:
num_max_boxes: 50
sample_transforms:
- Decode: {}
- Mixup: {alpha: 1.5, beta: 1.5}
- RandomDistort: {}
- RandomExpand: {fill_value: [123.675, 116.28, 103.53]}
- RandomCrop: {}
- RandomFlip: {}
batch_transforms:
- BatchRandomResize: {target_size: [320, 352, 384, 416, 448, 480, 512, 544, 576, 608], random_size: True, random_interp: True, keep_ratio: False}
- NormalizeBox: {}
- PadBox: {num_max_boxes: 50}
- BboxXYXY2XYWH: {}
- NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True}
- Permute: {}
- Gt2YoloTarget: {anchor_masks: [[6, 7, 8], [3, 4, 5], [0, 1, 2]], anchors: [[114,220],[148,252], [168,293], [193,328], [216,377], [218,261], [248,425], [264,341], [313,485]], downsample_ratios: [32, 16, 8]}
batch_size: 4
shuffle: true
drop_last: true
mixup_epoch: 250
use_shared_memory: true
EvalReader:
inputs_def:
num_max_boxes: 50
sample_transforms:
- Decode: {}
- Resize: {target_size: [608, 608], keep_ratio: False, interp: 2}
- NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True}
- Permute: {}
batch_size: 1
TestReader:
inputs_def:
image_shape: [3, 608, 608]
sample_transforms:
- Decode: {}
- Resize: {target_size: [608, 608], keep_ratio: False, interp: 2}
- NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True}
- Permute: {}
batch_size: 1
主要在这里面修改锚框和batchsize
(5)打开/PaddleDetection/configs/yolov3/_base_/yolov3_darknet53.yml
architecture: YOLOv3
pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/DarkNet53_pretrained.pdparams
norm_type: sync_bn
YOLOv3:
backbone: DarkNet
neck: YOLOv3FPN
yolo_head: YOLOv3Head
post_process: BBoxPostProcess
DarkNet:
depth: 53
return_idx: [2, 3, 4]
# use default config
# YOLOv3FPN:
YOLOv3Head:
anchors: [[114,220],[148,252], [168,293], [193,328], [216,377], [218,261], [248,425], [264,341], [313,485]]
anchor_masks: [[6, 7, 8], [3, 4, 5], [0, 1, 2]]
loss: YOLOv3Loss
YOLOv3Loss:
ignore_thresh: 0.7
downsample: [32, 16, 8]
label_smooth: false
BBoxPostProcess:
decode:
name: YOLOBox
conf_thresh: 0.005
downsample_ratio: 32
clip_bbox: true
nms:
name: MultiClassNMS
keep_top_k: 100
score_threshold: 0.01
nms_threshold: 0.45
nms_top_k: 1000
同样修改锚框
(6)打开/PaddleDetection/configs/datasets/voc.yml
metric: VOC
map_type: 11point
num_classes: 20
TrainDataset:
!VOCDataSet
dataset_dir: dataset/voc
anno_path: trainval.txt
label_list: label_list.txt
data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']
EvalDataset:
!VOCDataSet
dataset_dir: dataset/voc
anno_path: test.txt
label_list: label_list.txt
data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']
TestDataset:
!ImageFolder
anno_path: dataset/voc/label_list.txt
这里修改num_classes分类数
四、训练
cd PaddleDetection/
python tools/train.py -c configs/yolov3/yolov3_darknet53_270e_voc.yml
即可开始训练。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)