栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pp-picodet从环境配置到部署全流程(5)——参数配置说明

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pp-picodet从环境配置到部署全流程(5)——参数配置说明

pp-picodet模型参数配置
  • 前言
  • 1. 主配置文件
  • 2. 数据配置文件
  • 3. 运行时配置文件
  • 4. 模型配置文件
  • 5. 优化器配置文件
  • 6. 数据读取配置文件


前言

本文以picodet_xs_320_coco_lcnet.yml为例,详细介绍其中参数的含义以及需要注意的点,并能够以此为参照配置其他模型的参数。主配置文件picodet_xs_320_coco_lcnet.yml还依赖五个子配置文件,包括:coco_detection.yml、runtime.yml、picodet_v2.yml、optimizer_300e.yml、picodet_320_reader.yml。


1. 主配置文件

picodet_xs_320_coco_lcnet.yml

_BASE_: [         # 依赖五个子配置文件
  '../datasets/coco_detection.yml',    # 数据配置文件
  '../runtime.yml',                    # 运行时配置文件
  '_base_/picodet_v2.yml',             # 模型配置文件
  '_base_/optimizer_300e.yml',         # 优化器配置文件
  '_base_/picodet_320_reader.yml',     # 数据读取配置问件
]                       # 注意:主配置文件中的参数课覆盖子配置文件中的参数

pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/LCNet_x0_35_pretrained.pdparams    # 预训练模型下载地址
weights: output/picodet_xs_320_coco_lcnet/model_final      # 训练保存模型的路径,需要注意路径是否正确,否则验证或推理时报错
find_unused_parameters: True
use_ema: true
epoch: 300                  # 迭代次数,默认300
snapshot_epoch: 10          # 

LCNet:
  scale: 0.35
  feature_maps: [3, 4, 5]

LCPAN:
  out_channels: 96

PicoHeadV2:
  conv_feat:
    name: PicoFeat
    feat_in: 96
    feat_out: 96
    num_convs: 2
    num_fpn_stride: 4
    norm_type: bn
    share_cls_reg: True
    use_se: True
  feat_in_chan: 96

TrainReader:
  batch_size: 64

LearningRate:
  base_lr: 0.04
  schedulers:
  - !CosineDecay
    max_epochs: 300
  - !LinearWarmup
    start_factor: 0.1
    steps: 300
2. 数据配置文件

coco_detection.yml

# 数据评估类型
metric: COCO
# 数据集的类别数
num_classes: 3

# 训练集相关路径
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: ['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
    # 数据文件夹
    dataset_dir: dataset/coco

# 测试数据集相关路径
TestDataset:
  !ImageFolder
  	 # 标注文件路径,相对 dataset_dir 路径,os.path.join(dataset_dir, anno_path)
    anno_path: annotations/instances_val2017.json # also support txt (like VOC's label_list.txt)
    dataset_dir: dataset/coco # if set, anno_path will be 'dataset_dir/anno_path'

3. 运行时配置文件

runtime.yml

# 是否使用gpu
use_gpu: true
use_xpu: false
# 日志打印间隔
log_iter: 20
save_dir: output
# 模型保存间隔epoch
snapshot_epoch: 5      
print_flops: false

# Exporting the model
export:
  #导出模型时是否将后处理包含在网络中
  post_process: True  # Whether post-processing is included in the network when export model.
  #导出模型时是否将 NMS 包含在网络中。
  nms: True           # Whether NMS is included in the network when export model.
  #用于测试模型性能,如果设置为True,则不会导出后处理和NMS。
  benchmark: False    # It is used to testing model performance, if set `True`, post-process and NMS will not be exported.

4. 模型配置文件

picodet_v2.yml

# 网络结构名称
architecture: PicoDet
pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/LCNet_x1_5_pretrained.pdparams

PicoDet:
  backbone: LCNet
  neck: LCPAN
  head: PicoHeadV2

LCNet:
  scale: 1.5
  feature_maps: [3, 4, 5]

LCPAN:
  out_channels: 128
  use_depthwise: True
  num_features: 4

PicoHeadV2:
  conv_feat:
    name: PicoFeat
    feat_in: 128
    feat_out: 128
    num_convs: 4
    num_fpn_stride: 4
    norm_type: bn
    share_cls_reg: True
    use_se: True
  fpn_stride: [8, 16, 32, 64]
  feat_in_chan: 128
  prior_prob: 0.01
  reg_max: 7
  cell_offset: 0.5
  grid_cell_scale: 5.0
  static_assigner_epoch: 100
  use_align_head: True
  static_assigner:
    name: ATSSAssigner
    topk: 9
    force_gt_matching: False
  assigner:
    name: TaskAlignedAssigner
    topk: 13
    alpha: 1.0
    beta: 6.0
  loss_class:   # 分类损失
    name: VarifocalLoss
    use_sigmoid: False
    iou_weighted: True
    loss_weight: 1.0
  loss_dfl:     # 
    name: DistributionFocalLoss
    loss_weight: 0.5
  loss_bbox:    # bbox回归损失
    name: GIoULoss
    loss_weight: 2.5
  nms:
    name: MultiClassNMS
    nms_top_k: 1000
    keep_top_k: 100
    score_threshold: 0.025
    nms_threshold: 0.6         #  nms阈值


5. 优化器配置文件

optimizer_300e.yml

# 总训练轮数
epoch: 300

# 学习率设置
LearningRate:
  # 默认为8卡训学习率
  base_lr: 0.04
  # 学习率调整策略
  schedulers:
     # 余弦衰减
  - !CosineDecay
    max_epochs: 300
    # 线性预热
  - !LinearWarmup
    start_factor: 0.1
    steps: 300

# 优化器
OptimizerBuilder:
  optimizer:
    momentum: 0.9
    type: Momentum
  # 正则化
  regularizer:
    factor: 0.00004
    type: L2

6. 数据读取配置文件

picodet_320_reader.yml

# 每张GPU reader进程个数
worker_num: 6
# 输入网络图像的尺寸
eval_width: &eval_width 320
eval_height: &eval_height 320    
eval_size: &eval_size [*eval_height, *eval_width]

# 训练数据
TrainReader:
  # 训练数据transforms
  sample_transforms:
  - Decode: {} # 图片解码,将图片数据从numpy格式转为rgb格式,是必须存在的一个OP
  - RandomCrop: {}            # 随机裁剪
  - RandomFlip: {prob: 0.5}   # 随机翻转
  - RandomDistort: {}         # 随机颜色失真
  batch_transforms:
  - BatchRandomResize: {target_size: [256, 288, 320, 352, 384], random_size: True, random_interp: True, keep_ratio: False}
  - NormalizeImage: {is_scale: true, mean: [0.485,0.456,0.406], std: [0.229, 0.224,0.225]}
  - Permute: {}
  - PadGT: {}
  # 训练时batch_size
  batch_size: 64
  # 读取数据是是否乱序
  shuffle: true
  # 是否丢弃最后不能完整组成batch的数据
  drop_last: true


EvalReader:
  sample_transforms:
  - Decode: {}
  - Resize: {interp: 2, target_size: *eval_size, keep_ratio: False}
  - NormalizeImage: {is_scale: true, mean: [0.485,0.456,0.406], std: [0.229, 0.224,0.225]}
  - Permute: {}
  batch_transforms:
  - PadBatch: {pad_to_stride: 32}
  batch_size: 8
  shuffle: false


TestReader:
  inputs_def:
    image_shape: [1, 3, *eval_height, *eval_width]
  sample_transforms:
  - Decode: {}
  - Resize: {interp: 2, target_size: *eval_size, keep_ratio: False}
  - NormalizeImage: {is_scale: true, mean: [0.485,0.456,0.406], std: [0.229, 0.224,0.225]}
  - Permute: {}
  batch_size: 1


参考:
[1]:https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/docs/tutorials/config_annotation/ppyolo_r50vd_dcn_1x_coco_annotation.md

暑期编程PK赛 得CSDN机械键盘等精美礼品!
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1015437.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号