PPYOLO模型參數配置理解


內容參考自:README_cn.md · PaddlePaddle/PaddleDetection - 碼雲 - 開源中國 (gitee.com)

說明:用於幫助自己理解參數,后續會更新,可能有錯誤的地方,請不吝賜教。

# YOLO系列模型參數配置教程

標簽: 模型參數配置

++++++++++++++++++++++++++ppyolo_r18vd.yml++++++++++++++++++++++++++++++++architecture: YOLOv3 #模型的名稱use_gpu: true #是否使用GPU

max_iters: 15500 #最大的迭代次數 log_iter: 10     #輸出指定區間的平均結果,如10次的平均結果,也即打印log的間隔 save_dir: output snapshot_iter: 1550 metric: COCO pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet18_vd_pretrained.tar weights: output/ppyolo_r18/model_final num_classes: 9 use_fine_grained_loss: true use_ema: true ema_decay: 0.9998 YOLOv3: backbone: ResNet yolo_head: YOLOv3Head use_fine_grained_loss: true ResNet: norm_type: sync_bn freeze_at: 0 freeze_norm: false norm_decay: 0. depth: 18 feature_maps: [4, 5] variant: d YOLOv3Head: anchor_masks: [[3, 4, 5], [0, 1, 2]] anchors: [[10, 14], [23, 27], [37, 58], [81, 82], [135, 169], [344, 319]] norm_decay: 0. conv_block_num: 0 scale_x_y: 1.05 yolo_loss: YOLOv3Loss nms: MatrixNMS drop_block: true YOLOv3Loss: ignore_thresh: 0.7 scale_x_y: 1.05 label_smooth: false use_fine_grained_loss: true iou_loss: IouLoss IouLoss: loss_weight: 2.5 max_height: 640 max_width: 640 MatrixNMS: background_label: -1 keep_top_k: 100 normalized: false score_threshold: 0.01 post_threshold: 0.01 LearningRate: base_lr: 0.004 #學習率決定了權值更新的速度,學習率大,更新的就快,但太快容易越過最優值,而學習率太小又更新的慢,效率低,一般學習率隨着訓練的進行不斷更改,先高一點,然后慢慢降低 schedulers: - !PiecewiseDecay gamma: 0.1 milestones:#學習率變動因子:如迭代到10000次時,學習率衰減十倍,15000次迭代時,學習率又會在前一個學習率的基礎上衰減十倍 - 10000 - 15000 - !LinearWarmup start_factor: 0. steps: 4000 #學習率變動步長 OptimizerBuilder: optimizer: momentum: 0.9 #動量,影響梯度下降到最優的速度,一般默認0.9 type: Momentum regularizer: factor: 0.0005 #權重衰減正則系數,防止過擬合 type: L2 _READER_: 'ppyolo_reader.yml' TrainReader: inputs_def: fields: ['image', 'gt_bbox', 'gt_class', 'gt_score'] num_max_boxes: 50 dataset: !COCODataSet image_dir: images anno_path: annotations/val.json dataset_dir: /home/aistudio/data/data101204/NGdet_v4-concat with_background: false sample_transforms: - !DecodeImage to_rgb: True with_mixup: True - !MixupImage alpha: 1.5 beta: 1.5 - !ColorDistort {} - !RandomExpand fill_value: [123.675, 116.28, 103.53] - !RandomCrop {} - !RandomFlipImage is_normalized: false - !NormalizeBox {} - !PadBox num_max_boxes: 50 - !BboxXYXY2XYWH {} batch_transforms: - !RandomShape sizes: [ 352, 384, 416, 448, 480, 512, 544, 576, 608,640]
- !NormalizeImage mean: [0.485, 0.456, 0.406] std: [0.229, 0.224, 0.225] is_scale: True is_channel_first: false - !Permute to_bgr: false channel_first: True # Gt2YoloTarget is only used when use_fine_grained_loss set as true, # this operator will be deleted automatically if use_fine_grained_loss # is set as false - !Gt2YoloTarget anchor_masks: [[3, 4, 5], [0, 1, 2]]
  #anchors是可以事先通過cmd指令計算出來的,是和圖片數量,width,height以及cluster(就是下面的num的值,即想要使用的anchors的數量)相關的預選框,可以手工挑選,也可以通過k-means算法從訓練樣本中學出 anchors: [[10, 14], [23, 27], [37, 58], [81, 82], [135, 169], [344, 319]]
downsample_ratios: [32, 16] batch_size: 8 shuffle: true mixup_epoch: 100 #大於最大epoch,表示訓練過程一直使用mixup數據增廣 drop_last: true worker_num: 8 bufsize: 8 use_process: true

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

以`ppyolo_r50vd_dcn_1x_coco.yml`為例,這個模型由五個子配置文件組成:

- 數據配置文件 `coco_detection.yml`

```yaml
# 數據評估類型
metric: COCO
# 數據集的類別數
num_classes: 80

# TrainDataset
TrainDataset:
!COCODataSet
# 圖像數據路徑,相對 dataset_dir 路徑,os.path.join(dataset_dir, image_dir)
image_dir: train2017
# 標注文件路徑,相對 dataset_dir 路徑,os.path.join(dataset_dir, anno_path)
anno_path: annotations/instances_train2017.json
# 數據文件夾
dataset_dir: dataset/coco
# data_fields
data_fields: ['image', 'gt_bbox', 'gt_class', 'is_crowd']

EvalDataset:
!COCODataSet
# 圖像數據路徑,相對 dataset_dir 路徑,os.path.join(dataset_dir, image_dir)
image_dir: val2017
# 標注文件路徑,相對 dataset_dir 路徑,os.path.join(dataset_dir, anno_path)
anno_path: annotations/instances_val2017.json
# 數據文件夾,os.path.join(dataset_dir, anno_path)
dataset_dir: dataset/coco

TestDataset:
!ImageFolder
# 標注文件路徑,相對 dataset_dir 路徑
anno_path: annotations/instances_val2017.json
```

- 優化器配置文件 `optimizer_1x.yml`

```yaml
# 總訓練輪數
epoch: 405

# 學習率設置
LearningRate:
# 默認為8卡訓學習率
base_lr: 0.01
# 學習率調整策略
schedulers:
- !PiecewiseDecay
gamma: 0.1
# 學習率變化位置(輪數)
milestones:
- 243
- 324
# Warmup
- !LinearWarmup
start_factor: 0.
steps: 4000

# 優化器
OptimizerBuilder:
# 優化器
optimizer:
momentum: 0.9
type: Momentum
# 正則化
regularizer:
factor: 0.0005
type: L2
```

- 數據讀取配置文件 `ppyolo_reader.yml`

```yaml
# 每張GPU reader進程個數
worker_num: 2
# 訓練數據
TrainReader:
inputs_def:
num_max_boxes: 50
# 訓練數據transforms
sample_transforms:
- Decode: {}
- Mixup: {alpha: 1.5, beta: 1.5}
- RandomDistort: {}
- RandomExpand: {fill_value: [123.675, 116.28, 103.53]}
- RandomCrop: {}
- RandomFlip: {}
# batch_transforms
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: [[10, 13], [16, 30], [33, 23], [30, 61], [62, 45], [59, 119], [116, 90], [156, 198], [373, 326]], downsample_ratios: [32, 16, 8]}
# 訓練時batch_size
batch_size: 24
# 讀取數據是是否亂序
shuffle: true
# 是否丟棄最后不能完整組成batch的數據
drop_last: true
# mixup_epoch,大於最大epoch,表示訓練過程一直使用mixup數據增廣
mixup_epoch: 25000
# 是否通過共享內存進行數據讀取加速,需要保證共享內存大小(如/dev/shm)滿足大於1G
use_shared_memory: true

# 評估數據
EvalReader:
# 評估數據transforms
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
batch_size: 8
# 是否丟棄沒有標注的數據
drop_empty: false

# 測試數據
TestReader:
inputs_def:
image_shape: [3, 608, 608]
# 測試數據transforms
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
batch_size: 1
```

- 模型配置文件 `ppyolo_r50vd_dcn.yml`

```yaml
# 模型結構類型
architecture: YOLOv3
# 預訓練模型地址
pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/ResNet50_vd_ssld_pretrained.pdparams
# norm_type
norm_type: sync_bn
# 是否使用ema
use_ema: true
# ema_decay
ema_decay: 0.9998

# YOLOv3
YOLOv3:
# backbone
backbone: ResNet
# neck
neck: PPYOLOFPN
# yolo_head
yolo_head: YOLOv3Head
# post_process
post_process: BBoxPostProcess


# backbone
ResNet:
# depth
depth: 50
# variant
variant: d
# return_idx, 0 represent res2
return_idx: [1, 2, 3]
# dcn_v2_stages
dcn_v2_stages: [3]
# freeze_at
freeze_at: -1
# freeze_norm
freeze_norm: false
# norm_decay
norm_decay: 0.

# PPYOLOFPN
PPYOLOFPN:
# 是否coord_conv
coord_conv: true
# 是否drop_block
drop_block: true
# block_size
block_size: 3
# keep_prob
keep_prob: 0.9
# 是否spp
spp: true

# YOLOv3Head
YOLOv3Head:
# anchors
anchors: [[10, 13], [16, 30], [33, 23],
[30, 61], [62, 45], [59, 119],
[116, 90], [156, 198], [373, 326]]
# anchor_masks
anchor_masks: [[6, 7, 8], [3, 4, 5], [0, 1, 2]]
# loss
loss: YOLOv3Loss
# 是否使用iou_aware
iou_aware: true
# iou_aware_factor
iou_aware_factor: 0.4

# YOLOv3Loss
YOLOv3Loss:
# ignore_thresh
ignore_thresh: 0.7
# downsample
downsample: [32, 16, 8]
# 是否label_smooth
label_smooth: false
# scale_x_y
scale_x_y: 1.05
# iou_loss
iou_loss: IouLoss
# iou_aware_loss
iou_aware_loss: IouAwareLoss

# IouLoss
IouLoss:
loss_weight: 2.5
loss_square: true

# IouAwareLoss
IouAwareLoss:
loss_weight: 1.0

# BBoxPostProcess
BBoxPostProcess:
decode:
name: YOLOBox
conf_thresh: 0.01
downsample_ratio: 32
clip_bbox: true
scale_x_y: 1.05
# nms 配置
nms:
name: MatrixNMS
keep_top_k: 100
score_threshold: 0.01
post_threshold: 0.01
nms_top_k: -1
background_label: -1

```

- 運行時置文件 `runtime.yml`

```yaml
# 是否使用gpu
use_gpu: true
# 日志打印間隔
log_iter: 20
# save_dir
save_dir: output
# 模型保存間隔時間
snapshot_epoch: 1
```


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM