PaddleDetection icon indicating copy to clipboard operation
PaddleDetection copied to clipboard

PPYOLO+resnet50,在eval的时候报错

Open zhouyuxixixi opened this issue 5 years ago • 2 comments

我对yml文件进行了修改,如下

architecture: YOLOv3
use_gpu: true
max_iters: 2000
log_iter: 10
save_dir: output
snapshot_iter: 100
metric: VOC
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_ssld_pretrained.tar
weights: output/ppyolo/model_final
num_classes: 1
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: 50
  feature_maps: [3, 4, 5]
  variant: d
  dcn_v2_stages: [5]

YOLOv3Head:
  anchor_masks: [[6, 7, 8], [3, 4, 5], [0, 1, 2]]
  anchors: [[37, 45], [35, 49], [38, 45],
            [40, 44], [37, 48], [37, 54],
            [41, 49], [39, 52], [42, 52]]
  norm_decay: 0.
  coord_conv: true
  iou_aware: True
  iou_aware_factor: 0.4
  scale_x_y: 1.05
  spp: true
  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
  iou_aware_loss: IouAwareLoss

IouLoss:
  loss_weight: 2.5
  max_height: 448
  max_width: 448

IouAwareLoss:
  loss_weight: 1.0
  max_height: 448
  max_width: 448

MatrixNMS:
    background_label: -1
    keep_top_k: 100
    normalized: false
    score_threshold: 0.01
    post_threshold: 0.01

LearningRate:
  base_lr: 0.001
  schedulers:
  - !PiecewiseDecay
    gamma: 0.1
    milestones:
    - 800
    - 1400
  - !LinearWarmup
    start_factor: 0.
    steps: 200

OptimizerBuilder:
  optimizer:
    momentum: 0.9
    type: Momentum
  regularizer:
    factor: 0.0005
    type: L2

_READER_: 'ppyolo_reader_my.yml'

TrainReader:
  inputs_def:
    fields: ['image', 'gt_bbox', 'gt_class', 'gt_score']
    num_max_boxes: 20
  dataset:
    !VOCDataSet
      anno_path: train_detection.txt
      dataset_dir: E:\\DeepLearning\\DataSet\\Cigarette\\OnlyGoodCigarettePaddleDetectionCopy
      use_default_label: False
      with_background: false
  sample_transforms:
    - !DecodeImage
      to_rgb: True
#      with_mixup: True
    - !ResizeImage
      target_size: 448
      max_size: 448
#    - !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: 20
    - !BboxXYXY2XYWH {}
  batch_transforms:
  - !RandomShape
#    sizes: [320, 352, 384, 416, 448, 480, 512, 544, 576, 608]
    sizes: [448]
    random_inter: True
  - !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: [[6, 7, 8], [3, 4, 5], [0, 1, 2]]
    anchors: [[37, 45], [35, 49], [38, 45],
              [40, 44], [37, 48], [37, 54],
              [41, 49], [39, 52], [42, 52]]
    downsample_ratios: [32, 16, 8]
  batch_size: 2
  shuffle: true
  mixup_epoch: 1000
  drop_last: true
  worker_num: 1
  bufsize: 1
  use_process: False

EvalReader:
  inputs_def:
#    fields: ['image', 'im_size', 'im_id']
    fields: ['image', 'im_size', 'im_id', 'gt_bbox', 'gt_class', 'is_difficult']
    num_max_boxes: 20
  dataset:
    !VOCDataSet
      anno_path: eval_detection.txt
      dataset_dir: E:\\DeepLearning\\DataSet\\Cigarette\\OnlyGoodCigarettePaddleDetectionCopy
      use_default_label: False
      with_background: false
  sample_transforms:
    - !DecodeImage
      to_rgb: True
    - !ResizeImage
      target_size: 448
      max_size: 448
#      interp: 2
    - !NormalizeImage
      mean: [0.485, 0.456, 0.406]
      std: [0.229, 0.224, 0.225]
      is_scale: True
      is_channel_first: false
    - !PadBox
      num_max_boxes: 20
    - !Permute
      to_bgr: false
      channel_first: True
  batch_size: 1
  drop_empty: false
  worker_num: 1
  bufsize: 1

训练过程正常,当预测的时候报错

InvalidArgumentError: The 2-th dimension of input[0] and input[1] is expected to be equal.But received input[0]'s shape = [1, 256, 20, 28], input[1]'s shape = [1, 1024, 19, 28].
  [Hint: Expected inputs_dims[0][j] == inputs_dims[i][j], but received inputs_dims[0][j]:20 != inputs_dims[i][j]:19.] (at D:\2.0.0-rc0\paddle\paddle/fluid/operators/concat_op.h:63)
  [operator < concat > error]

下面是我按照相同方法修改resnet18的,这个能够正常运行

architecture: YOLOv3
use_gpu: true
max_iters: 2000
log_iter: 10
save_dir: output
snapshot_iter: 100
metric: VOC
pretrain_weights:
weights: output/ppyolo_tiny/model_final
num_classes: 1
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]]
  anchors: [[19, 22], [18, 24], [19, 23],
            [20, 25], [19, 26], [21, 25]]
  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: 608
  max_width: 608

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:
    - 150000
    - 200000
  - !LinearWarmup
    start_factor: 0.
    steps: 4000

OptimizerBuilder:
  optimizer:
    momentum: 0.9
    type: Momentum
  regularizer:
    factor: 0.0005
    type: L2

_READER_: 'ppyolo_reader_my.yml'
TrainReader:
  inputs_def:
    fields: ['image', 'gt_bbox', 'gt_class', 'gt_score']
    num_max_boxes: 20
  dataset:
    !VOCDataSet
      anno_path: train_detection.txt
      dataset_dir: E:\\DeepLearning\\DataSet\\Cigarette\\OnlyGoodCigarettePaddleDetectionCopy
      use_default_label: False
      with_background: false
  sample_transforms:
    - !DecodeImage
      to_rgb: True
#      with_mixup: True
    - !ResizeImage
      target_size: 224
      max_size: 224
#    - !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: 20
    - !BboxXYXY2XYWH {}
  batch_transforms:
  - !RandomShape
#    sizes: [320, 352, 384, 416, 448, 480, 512, 544, 576, 608]
    sizes: [224]
    random_inter: True
  - !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: [[19, 22], [18, 24], [19, 23],
              [20, 25], [19, 26], [21, 25]]
    downsample_ratios: [32, 16]
  batch_size: 4
  shuffle: true
  mixup_epoch: 500
  drop_last: true
  worker_num: 1
  bufsize: 1
  use_process: False

EvalReader:
  inputs_def:
#    fields: ['image', 'im_size', 'im_id']
    fields: ['image', 'im_size', 'im_id', 'gt_bbox', 'gt_class', 'is_difficult']
    num_max_boxes: 20
  dataset:
    !VOCDataSet
      anno_path: eval_detection.txt
      dataset_dir: E:\\DeepLearning\\DataSet\\Cigarette\\OnlyGoodCigarettePaddleDetectionCopy
      use_default_label: False
      with_background: false
  sample_transforms:
    - !DecodeImage
      to_rgb: True
    - !ResizeImage
      target_size: 224
      max_size: 224
#      interp: 2
    - !NormalizeImage
      mean: [0.485, 0.456, 0.406]
      std: [0.229, 0.224, 0.225]
      is_scale: True
      is_channel_first: false
    - !PadBox
      num_max_boxes: 20
    - !Permute
      to_bgr: false
      channel_first: True
  batch_size: 1
  drop_empty: false
  worker_num: 1
  bufsize: 1

他们的eval部分是相同的,只是送入图像的尺寸不同

请问为啥会报这个错误

zhouyuxixixi avatar Dec 19 '20 05:12 zhouyuxixixi

请不要设置maxsize,具体原因,我也不清楚,当去除maxsize之后,eval正常,我也无法理解 只需要设置targetsize,就可以让送入的图像变为正方形

zhouyuxixixi avatar Dec 19 '20 05:12 zhouyuxixixi

设置maxsize时,回依据maxsize计算最终resize之后的变长,等比例resize。不是resize到正方形。

https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.0-beta/ppdet/data/transform/operators.py#L324

PP-YOLO/YOLOv3系列模型需要resize到定长。不能设置maxsize。

qingqing01 avatar Dec 21 '20 02:12 qingqing01