_BASE_: [
  '../../fcos/fcos_r50_fpn_iou_multiscale_2x_coco.yml',
  '../_base_/coco_detection_percent_10.yml',
]
log_iter: 50
snapshot_epoch: 5
epochs: &epochs 240
weights: output/denseteacher_fcos_r50_fpn_coco_semi010/model_final


### pretrain and warmup config, choose one and comment another
# pretrain_weights: https://bj.bcebos.com/v1/paddledet/models/fcos_r50_fpn_2x_coco_sup010.pdparams # mAP=26.3
# semi_start_iters: 0
# ema_start_iters: 0
# use_warmup: &use_warmup False

pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/ResNet50_cos_pretrained.pdparams
semi_start_iters: 5000
ema_start_iters: 3000
use_warmup: &use_warmup True


### global config
use_simple_ema: True
ema_decay: 0.9996
ssod_method: DenseTeacher
DenseTeacher:
  train_cfg:
    sup_weight: 1.0
    unsup_weight: 1.0
    loss_weight: {distill_loss_cls: 4.0, distill_loss_box: 1.0, distill_loss_quality: 1.0}
    concat_sup_data: True
    suppress: linear
    ratio: 0.01
    gamma: 2.0
  test_cfg:
    inference_on: teacher


### reader config
worker_num: 2
SemiTrainReader:
  sample_transforms:
    - Decode: {}
    - RandomResize: {target_size: [[640, 1333], [672, 1333], [704, 1333], [736, 1333], [768, 1333], [800, 1333]], keep_ratio: True, interp: 1}
    - RandomFlip: {}
  weak_aug:
    - NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: true}
  strong_aug:
    - StrongAugImage: {transforms: [
        RandomColorJitter: {prob: 0.8, brightness: 0.4, contrast: 0.4, saturation: 0.4, hue: 0.1},
        RandomErasingCrop: {},
        RandomGaussianBlur: {prob: 0.5, sigma: [0.1, 2.0]},
        RandomGrayscale: {prob: 0.2},
      ]}
    - NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: true}
  sup_batch_transforms:
    - Permute: {}
    - PadBatch: {pad_to_stride: 32}
    - Gt2FCOSTarget:
        object_sizes_boundary: [64, 128, 256, 512]
        center_sampling_radius: 1.5
        downsample_ratios: [8, 16, 32, 64, 128]
        num_shift: 0. # default 0.5
        multiply_strides_reg_targets: False
        norm_reg_targets: True
  unsup_batch_transforms:
    - Permute: {}
    - PadBatch: {pad_to_stride: 32}
  sup_batch_size: 2
  unsup_batch_size: 2
  shuffle: True
  drop_last: True

EvalReader:
  sample_transforms:
    - Decode: {}
    - Resize: {target_size: [800, 1333], keep_ratio: True, interp: 1}
    - NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True}
    - Permute: {}
  batch_transforms:
    - PadBatch: {pad_to_stride: 32}
  batch_size: 1

TestReader:
  sample_transforms:
    - Decode: {}
    - Resize: {target_size: [800, 1333], keep_ratio: True, interp: 1}
    - NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True}
    - Permute: {}
  batch_transforms:
    - PadBatch: {pad_to_stride: 32}
  batch_size: 1
  fuse_normalize: True


### model config
architecture: FCOS
FCOS:
  backbone: ResNet
  neck: FPN
  fcos_head: FCOSHead

ResNet:
  depth: 50
  variant: 'b'
  norm_type: bn
  freeze_at: 0 # res2
  return_idx: [1, 2, 3]
  num_stages: 4

FPN:
  out_channel: 256
  spatial_scales: [0.125, 0.0625, 0.03125]
  extra_stage: 2
  has_extra_convs: True
  use_c5: False

FCOSHead:
  fcos_feat:
    name: FCOSFeat
    feat_in: 256
    feat_out: 256
    num_convs: 4
    norm_type: "gn"
    use_dcn: False
  fpn_stride: [8, 16, 32, 64, 128]
  prior_prob: 0.01
  norm_reg_targets: True
  centerness_on_reg: True
  num_shift: 0. # default 0.5
  multiply_strides_reg_targets: False
  sqrt_score: False
  fcos_loss:
    name: FCOSLoss
    loss_alpha: 0.25
    loss_gamma: 2.0
    iou_loss_type: "giou"
    reg_weights: 1.0
    quality: "iou"
  nms:
    name: MultiClassNMS
    nms_top_k: 1000
    keep_top_k: 100
    score_threshold: 0.025
    nms_threshold: 0.6


### other config
epoch: *epochs
LearningRate:
  base_lr: 0.01
  schedulers:
  - !PiecewiseDecay
    gamma: 0.1
    milestones: [*epochs]
    use_warmup: *use_warmup
  - !LinearWarmup
    start_factor: 0.001
    steps: 1000

OptimizerBuilder:
  optimizer:
    momentum: 0.9
    type: Momentum
  regularizer:
    factor: 0.0001
    type: L2
  clip_grad_by_value: 1.0
