PaddlePaddle / PaddleDetection

Object Detection toolkit based on PaddlePaddle. It supports object detection, instance segmentation, multiple object tracking and real-time multi-person keypoint detection.
Apache License 2.0
12.79k stars 2.89k forks source link

faster rcnn 使用vgg16做骨干网络,生成yml配置文件问题 #2272

Closed AngZhai closed 1 year ago

AngZhai commented 3 years ago

使用VGG16作为faster rcnn的骨干网络,文件内容如下:

architecture: FasterRCNN
use_gpu: true
max_iters: 16000
log_iter: 50
save_dir: output
snapshot_iter: 200
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO
weights: output/faster_rcnn_vgg/model_final
num_classes: 5

FasterRCNN:
  backbone: VGG
  fpn: null
  rpn_head: RPNHead
  roi_extractor: RoIAlign
  bbox_head: BBoxHead
  bbox_assigner: BBoxAssigner
  rpn_only: false

VGG:
  depth: 16
  extra_block_filters:
  - - 256
    - 512
    - 1
    - 2
    - 3
  - - 128
    - 256
    - 1
    - 2
    - 3
  - - 128
    - 256
    - 0
    - 1
    - 3
  - - 128
    - 256
    - 0
    - 1
    - 3
  normalizations:
  - 20.0
  - -1
  - -1
  - -1
  - -1
  - -1
  with_extra_blocks: false

ResNetC5:
  depth: 50
  norm_type: affine_channel

RPNHead:
  anchor_generator:
    anchor_sizes:
    - 32
    - 64
    - 128
    - 256
    - 512
    aspect_ratios:
    - 0.5
    - 1.0
    - 2.0
    stride:
    - 16.0
    - 16.0
    variance:
    - 1.0
    - 1.0
    - 1.0
    - 1.0
  num_classes: 1
  rpn_target_assign:
    rpn_batch_size_per_im: 256
    rpn_fg_fraction: 0.5
    rpn_negative_overlap: 0.3
    rpn_positive_overlap: 0.7
    rpn_straddle_thresh: 0.0
    use_random: true
  test_proposal:
    eta: 1.0
    min_size: 0.1
    nms_thresh: 0.5
    post_nms_top_n: 1000
    pre_nms_top_n: 6000
  train_proposal:
    eta: 1.0
    min_size: 0.1
    nms_thresh: 0.5
    post_nms_top_n: 2000
    pre_nms_top_n: 12000

RoIAlign:
  resolution: 7
  sampling_ratio: 0
  spatial_scale: 0.0625

BBoxAssigner:
  batch_size_per_im: 512
  bbox_reg_weights:
  - 0.1
  - 0.1
  - 0.2
  - 0.2
  bg_thresh_hi: 0.5
  bg_thresh_lo: 0.0
  fg_fraction: 0.25
  fg_thresh: 0.5
  num_classes: 81
  shuffle_before_sample: true

BBoxHead:
  bbox_loss:
    sigma: 1.0
  box_coder:
    axis: 1
    box_normalized: false
    code_type: decode_center_size
    prior_box_var:
    - 0.1
    - 0.1
    - 0.2
    - 0.2
  head: ResNetC5
  nms:
    background_label: 0
    keep_top_k: 100
    nms_eta: 1.0
    nms_threshold: 0.5
    nms_top_k: -1
    normalized: false
    score_threshold: 0.05
  num_classes: 5

LearningRate:
  base_lr: 0.001
  schedulers:
  - !PiecewiseDecay
    gamma:
    - 0.1
    - 0.1
    milestones:
    - 60000
    - 80000
    values: null
  - !LinearWarmup
    start_factor: 0.3333333333333333
    steps: 500

OptimizerBuilder:
  clip_grad_by_norm: null
  optimizer:
    momentum: 0.9
    type: Momentum
  regularizer:
    factor: 0.0001
    type: L2
_READER_: 'faster_reader.yml'

当我使用python tools/train.py -c configs/faster_vgg.yml -o use_gpu=true --use_vdl=True --vdl_log_dir=vdl_dir/scalar --eval训练的时候,报如下错误:

Traceback (most recent call last):
  File "tools/train.py", line 399, in <module>
    main()
  File "tools/train.py", line 136, in main
    train_fetches = model.train(feed_vars)
  File "/home/aistudio/PaddleDetection/ppdet/modeling/architectures/faster_rcnn.py", line 240, in train
    return self.build(feed_vars, 'train')
  File "/home/aistudio/PaddleDetection/ppdet/modeling/architectures/faster_rcnn.py", line 90, in build
    body_feat_names = list(body_feats.keys())
AttributeError: 'Variable' object has no attribute 'keys'

请问我哪里配置出错了吗

qingqing01 commented 3 years ago

@AngZhai

FasterRCNN接受的backbone返回的是dict

如ResNet:

https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.0-rc/ppdet/modeling/backbones/resnet.py#L483

如MobileNetv3 https://github.com/PaddlePaddle/PaddleDetection/blob/b11b3932a1f9ee9226683a632c2c60b7f2c2fee4/ppdet/modeling/backbones/mobilenet_v3.py#L565

因此VGG这里需要类似如上方式修改下

https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.0-rc/ppdet/modeling/backbones/vgg.py#L70

AngZhai commented 3 years ago

@qingqing01 您好,感谢您的回复,我将 return layers 改为 return OrderedDict([('vgg16{}_'.format(layers[k]), v) for k, v in enumerate(layers)]) 目前仍然是这个错误: Traceback (most recent call last): File "tools/train.py", line 403, in main() File "tools/train.py", line 140, in main train_fetches = model.train(feed_vars) File "/home/aistudio/PaddleDetection/ppdet/modeling/architectures/faster_rcnn.py", line 240, in train return self.build(feed_vars, 'train') File "/home/aistudio/PaddleDetection/ppdet/modeling/architectures/faster_rcnn.py", line 90, in build body_feat_names = list(body_feats.keys()) AttributeError: 'Variable' object has no attribute 'keys' 是我改的不对吗

thinkthinking commented 1 year ago

欢迎使用PaddleDetection,如有问题可以reopen