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.8k stars 2.89k forks source link

The number of valid bbox detected is zero #2266

Closed xmk011235 closed 1 year ago

xmk011235 commented 3 years ago

在《新手入门第五课-PaddleDetection十分钟上手》项目中,使用https://paddlemodels.bj.bcebos.com/object_detection/cascade_rcnn_dcn_r50_fpn_1x.tar 进行迁移学习, 训练过程出现The number of valid bbox detected is zero,请教原因。 个人经过如下排查:

  1. 貌似只有dcn的预训练模型才会出现上面的问题,使用其他非dcn预训练模型进行迁移学习不会出现这个问题;
  2. 应该不是环境问题,测试两个环境没有区别:paddle1.8.4+detection0.4,和paddle2.0+detection0.5;
  3. yml配置应该不会有啥问题,也用更小的学习率测试,问题同样在;
  4. 也不是数据集的问题,测试过roadsign、PBC等数据集。

个人结论:问题可能出在dcn的预训练模型!

附件: 使用roadsign_coco数据集,yml如下:

architecture: CascadeRCNN
use_gpu: true
max_iters: 9600
log_smooth_window: 20
save_dir: output
snapshot_iter: 800
metric: COCO
pretrain_weights: https://paddlemodels.bj.bcebos.com/object_detection/cascade_rcnn_dcn_r50_fpn_1x.tar
weights: output/f2/best_model
num_classes: 5
finetune_exclude_pretrained_params: ['cls_score, bbox_pred']

CascadeRCNN:
  backbone: ResNet
  fpn: FPN
  rpn_head: FPNRPNHead
  roi_extractor: FPNRoIAlign
  bbox_head: CascadeBBoxHead
  bbox_assigner: CascadeBBoxAssigner

ResNet:
  norm_type: affine_channel
  depth: 50
  feature_maps: [2, 3, 4, 5]
  freeze_at: 2
  variant: b
  dcn_v2_stages: [3, 4, 5]

FPN:
  max_level: 6
  min_level: 2
  num_chan: 256
  spatial_scale: [0.03125, 0.0625, 0.125, 0.25]
FPNRPNHead:
  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]
  anchor_start_size: 32
  min_level: 2
  max_level: 6
  num_chan: 256
  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
  train_proposal:
    min_size: 0.0
    nms_thresh: 0.7
    pre_nms_top_n: 2000
    post_nms_top_n: 2000
  test_proposal:
    min_size: 0.0
    nms_thresh: 0.7
    pre_nms_top_n: 1000
    post_nms_top_n: 1000
FPNRoIAlign:
  canconical_level: 4
  canonical_size: 224
  max_level: 5
  min_level: 2
  sampling_ratio: 2
  box_resolution: 7

CascadeBBoxAssigner:
  batch_size_per_im: 512
  bbox_reg_weights: [10, 20, 30]
  bg_thresh_lo: [0.0, 0.0, 0.0]
  bg_thresh_hi: [0.5, 0.6, 0.7]
  fg_thresh: [0.5, 0.6, 0.7]
  fg_fraction: 0.25
CascadeBBoxHead:
  head: CascadeTwoFCHead
  nms:
    keep_top_k: 100
    nms_threshold: 0.5
    score_threshold: 0.05
CascadeTwoFCHead:
  mlp_dim: 1024

LearningRate:
  base_lr: 0.0001
  schedulers:
  - !PiecewiseDecay
    gamma: 0.1
    milestones:
    - 6400
    - 8800
  - !LinearWarmup
    start_factor: 0.3333333333333333
    steps: 100
OptimizerBuilder:
  optimizer:
    momentum: 0.9
    type: Momentum
  regularizer:
    factor: 0.0001
    type: L2

#####################################数据配置#####################################
TrainReader:
  inputs_def:
    fields: ['image', 'im_info', 'im_id', 'gt_bbox', 'gt_class', 'is_crowd']
  dataset:
    !COCODataSet
    dataset_dir: dataset/roadsign_coco
    image_dir: images
    anno_path: annotations/train.json
    with_background: true
  batch_size: 1
  bufsize: 2
  shuffle: true
  drop_empty: true
  drop_last: true
  mixup_epoch: -1
  use_process: true
  worker_num: 4
  sample_transforms:
  - !DecodeImage
    to_rgb: true
  - !RandomFlipImage
    is_normalized: true
    prob: 0.5
  - !NormalizeImage
    mean: [0.485, 0.456, 0.406]
    std: [0.229, 0.224, 0.225]
    is_scale: true
    is_channel_first: false
  - !ResizeImage
    target_size: 800
    max_size: 1333
    interp: 1
    use_cv2: true
  - !Permute
    channel_first: true
    to_bgr: false
  batch_transforms:
  - !PadBatch
    pad_to_stride: 32
    use_padded_im_info: false

EvalReader:
  batch_size: 1
  bufsize: 2
  shuffle: false
  drop_empty: false
  drop_last: false
  use_process: true
  worker_num: 4
  inputs_def:
    fields: ['image', 'im_info', 'im_id', 'im_shape']
  dataset:
    !COCODataSet
    dataset_dir: dataset/roadsign_coco
    image_dir: images
    anno_path: annotations/valid.json
    with_background: true
  sample_transforms:
  - !DecodeImage
    to_rgb: true
  - !NormalizeImage
    mean: [0.485, 0.456, 0.406]
    std: [0.229, 0.224, 0.225]
    is_scale: true
    is_channel_first: false
  - !ResizeImage
    target_size: 800
    max_size: 1333
    interp: 1
    use_cv2: true
  - !Permute
    to_bgr: false
    channel_first: true
  batch_transforms:
  - !PadBatch
    pad_to_stride: 32
    use_padded_im_info: true

TestReader:
  batch_size: 1
  drop_empty: false
  drop_last: false
  inputs_def:
    fields: ['image', 'im_info', 'im_id', 'im_shape']
  dataset:
    !ImageFolder
    anno_path: annotations/valid.json
    with_background: true
  sample_transforms:
  - !DecodeImage
    to_rgb: true
    with_mixup: false
  - !NormalizeImage
    mean: [0.485, 0.456, 0.406]
    std: [0.229, 0.224, 0.225]
    is_scale: true
    is_channel_first: false
  - !ResizeImage
    target_size: 800
    max_size: 1333
    interp: 1
    use_cv2: true
  - !Permute
    to_bgr: false
    channel_first: true
  batch_transforms:
  - !PadBatch
    pad_to_stride: 32
    use_padded_im_info: true
heavengate commented 3 years ago

您好,The number of valid bbox detected is zero是在训练多少iter评估的时候报的呢,多训练一些iter试下呢

xmk011235 commented 3 years ago

您好,The number of valid bbox detected is zero是在训练多少iter评估的时候报的呢,多训练一些iter试下呢

全程都是这样的结果,map从始至终都是0。我已经测试很久了,建议你复现一下,我怀疑是paddleDetection框架的问题

thinkthinking commented 1 year ago

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