text: _base_ = [
      './_base_/models/cascade_mask_rcnn_swin_fpn.py',
      './_base_/schedules/schedule_1x.py', './_base_/default_runtime.py']
  
  
  model = dict(
      pretrained='https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth',
      backbone=dict(
          embed_dim=96,
          depths=[2, 2, 6, 2],
          num_heads=[3, 6, 12, 24],
          window_size=7,
          ape=True,
          drop_path_rate=0.2,
          patch_norm=True,
          use_checkpoint=True
      ),
      neck=dict(in_channels=[96, 192, 384, 768]),
          rpn_head=dict(
          type='RPNHead',
          in_channels=256,
          feat_channels=256,
          anchor_generator=dict(
              type='AnchorGenerator',
              scales=[8],
              ratios=[0.5, 1.0, 2.0],
              strides=[4, 8, 16, 32, 64]),
          bbox_coder=dict(
              type='DeltaXYWHBBoxCoder',
              target_means=[.0, .0, .0, .0],
              target_stds=[1.0, 1.0, 1.0, 1.0]),
          loss_cls=dict(
              type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
          loss_bbox=dict(type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0)),
      roi_head=dict(
          bbox_head=[
              dict(
                  type='ConvFCBBoxHead',
                  num_shared_convs=4,
                  num_shared_fcs=1,
                  in_channels=256,
                  conv_out_channels=256,
                  fc_out_channels=1024,
                  roi_feat_size=7,
                  num_classes=5,
                  bbox_coder=dict(
                      type='DeltaXYWHBBoxCoder',
                      target_means=[0., 0., 0., 0.],
                      target_stds=[0.1, 0.1, 0.2, 0.2]),
                  reg_class_agnostic=False,
                  reg_decoded_bbox=True,
                  loss_cls=dict(
                      type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0),
                  loss_bbox=dict(type='GIoULoss', loss_weight=10.0)),
              dict(
                  type='ConvFCBBoxHead',
                  num_shared_convs=4,
                  num_shared_fcs=1,
                  in_channels=256,
                  conv_out_channels=256,
                  fc_out_channels=1024,
                  roi_feat_size=7,
                  num_classes=5,
                  bbox_coder=dict(
                      type='DeltaXYWHBBoxCoder',
                      target_means=[0., 0., 0., 0.],
                      target_stds=[0.05, 0.05, 0.1, 0.1]),
                  reg_class_agnostic=False,
                  reg_decoded_bbox=True,
                  loss_cls=dict(
                      type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0),
                  loss_bbox=dict(type='GIoULoss', loss_weight=10.0)),
              dict(
                  type='ConvFCBBoxHead',
                  num_shared_convs=4,
                  num_shared_fcs=1,
                  in_channels=256,
                  conv_out_channels=256,
                  fc_out_channels=1024,
                  roi_feat_size=7,
                  num_classes=5,
                  bbox_coder=dict(
                      type='DeltaXYWHBBoxCoder',
                      target_means=[0., 0., 0., 0.],
                      target_stds=[0.033, 0.033, 0.067, 0.067]),
                  reg_class_agnostic=False,
                  reg_decoded_bbox=True,
                  loss_cls=dict(
                      type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0),
                  loss_bbox=dict(type='GIoULoss', loss_weight=10.0))
          ],
          mask_roi_extractor=None,
          mask_head=None),
          test_cfg = dict(
              rpn=dict(
                  nms_across_levels=False,
                  nms_pre=2000,
                  nms_post=2000,
                  max_per_img=2000,
                  nms=dict(type='nms', iou_threshold=0.7),
                  min_bbox_size=0),
              rcnn=dict(
                  score_thr=0.05,
                  nms=dict(type='nms', iou_threshold=0.5),
                  max_per_img=100,
                  mask_thr_binary=0.5)))
  
  img_norm_cfg = dict(
      mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
  
  # augmentation strategy originates from DETR / Sparse RCNN
  train_pipeline = [
      dict(type='LoadImageFromFile'),
      dict(type='LoadAnnotations', with_bbox=True, with_mask=False),
      dict(type='RandomFlip', flip_ratio=0.5),
      dict(type='AutoAugment',
           policies=[
               [
                   dict(type='Resize',
                        img_scale=[(640, 1000), (672, 1000), (704, 1000),
                                   (736, 1000), (768, 1000), (800, 1000),
                                   (1000,1000)],
                        multiscale_mode='value',
                        keep_ratio=True)
               ],
               [
                   dict(type='Resize',
                        img_scale=[(400, 1000), (500, 1000), (600, 1000)],
                        multiscale_mode='value',
                        keep_ratio=True),
                   dict(type='RandomCrop',
                        crop_type='absolute_range',
                        crop_size=(384, 600),
                        allow_negative_crop=True),
                   dict(type='Resize',
                        img_scale=[(640, 1000),
                                   (672, 1000), (704, 1000), (736, 1000),
                                   (768, 1000), (800, 1000), (1000,1000)],
                        multiscale_mode='value',
                        override=True,
                        keep_ratio=True)
               ]
           ]),
      dict(type='Normalize', **img_norm_cfg),
      dict(type='Pad', size_divisor=32),
      dict(type='DefaultFormatBundle'),
      dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']),
  ]
  val_pipeline = [
      dict(type='LoadImageFromFile'),
      dict(
          type='MultiScaleFlipAug',
          img_scale=(1333, 800),
          flip=False,
          transforms=[
              dict(type='Resize', keep_ratio=True),
              dict(type='RandomFlip'),
              dict(type='Normalize', **img_norm_cfg),
              dict(type='Pad', size_divisor=32),
              dict(type='ImageToTensor', keys=['img']),
              dict(type='Collect', keys=['img']),
          ])
  ]
  
  test_pipeline = [
      dict(type='LoadImageFromFile'),
      dict(
          type='MultiScaleFlipAug',
          img_scale=(2500, 1600),
          flip=False,
          transforms=[
              dict(type='Resize', keep_ratio=True),
              dict(type='RandomFlip'),
              dict(type='Normalize', **img_norm_cfg),
              dict(type='Pad', size_divisor=32),
              dict(type='ImageToTensor', keys=['img']),
              dict(type='Collect', keys=['img']),
          ])
  ]
  
  
  optimizer = dict(_delete_=True, type='AdamW', lr=0.0001, betas=(0.9, 0.999), weight_decay=0.05,
                   paramwise_cfg=dict(custom_keys={'absolute_pos_embed': dict(decay_mult=0.),
                                                   'relative_position_bias_table': dict(decay_mult=0.),
                                                   'norm': dict(decay_mult=0.)}))
  lr_config = dict(step=[8, 11])
  
  dataset_type = 'CocoDataset'
  classes = ('Crack', 'Spallation', 'Efflorescence', 'ExposedBars', 'CorrosionStain')
  data_root = 'data/codebrim_coco/'
  data = dict(
      samples_per_gpu=2,
      workers_per_gpu=0,
     train=dict(
          type=dataset_type,
          # explicitly add your class names to the field `classes`
          classes=classes,
          ann_file=data_root + 'annotations/codebrim_train.json',
          img_prefix=data_root + 'train/',
          pipeline=train_pipeline),
      val=dict(
          type=dataset_type,
          # explicitly add your class names to the field `classes`
          classes=classes,
          ann_file=data_root + 'annotations/codebrim_val.json',
          img_prefix=data_root + 'val/',
          pipeline=val_pipeline),
      test=dict(
          type=dataset_type,
          # explicitly add your class names to the field `classes`
          classes=classes,
          ann_file=data_root + 'annotations/codebrim_val.json',
          img_prefix=data_root + 'val/',
          pipeline=test_pipeline))
  
  evaluation = dict(metric=['bbox'], classwise=True)
  
  
  runner = dict(type='EpochBasedRunner', max_epochs=150)
  checkpoint_config = dict(interval=25) # Saves checkpoint every 50 epoch
  