dab-detr_r50_8xb2-50e_coco.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. _base_ = [
  2. '../_base_/datasets/coco_detection.py', '../_base_/default_runtime.py'
  3. ]
  4. model = dict(
  5. type='DABDETR',
  6. num_queries=300,
  7. with_random_refpoints=False,
  8. num_patterns=0,
  9. data_preprocessor=dict(
  10. type='DetDataPreprocessor',
  11. mean=[123.675, 116.28, 103.53],
  12. std=[58.395, 57.12, 57.375],
  13. bgr_to_rgb=True,
  14. pad_size_divisor=1),
  15. backbone=dict(
  16. type='ResNet',
  17. depth=50,
  18. num_stages=4,
  19. out_indices=(3, ),
  20. frozen_stages=1,
  21. norm_cfg=dict(type='BN', requires_grad=False),
  22. norm_eval=True,
  23. style='pytorch',
  24. init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
  25. neck=dict(
  26. type='ChannelMapper',
  27. in_channels=[2048],
  28. kernel_size=1,
  29. out_channels=256,
  30. act_cfg=None,
  31. norm_cfg=None,
  32. num_outs=1),
  33. encoder=dict(
  34. num_layers=6,
  35. layer_cfg=dict(
  36. self_attn_cfg=dict(
  37. embed_dims=256, num_heads=8, dropout=0., batch_first=True),
  38. ffn_cfg=dict(
  39. embed_dims=256,
  40. feedforward_channels=2048,
  41. num_fcs=2,
  42. ffn_drop=0.,
  43. act_cfg=dict(type='PReLU')))),
  44. decoder=dict(
  45. num_layers=6,
  46. query_dim=4,
  47. query_scale_type='cond_elewise',
  48. with_modulated_hw_attn=True,
  49. layer_cfg=dict(
  50. self_attn_cfg=dict(
  51. embed_dims=256,
  52. num_heads=8,
  53. attn_drop=0.,
  54. proj_drop=0.,
  55. cross_attn=False),
  56. cross_attn_cfg=dict(
  57. embed_dims=256,
  58. num_heads=8,
  59. attn_drop=0.,
  60. proj_drop=0.,
  61. cross_attn=True),
  62. ffn_cfg=dict(
  63. embed_dims=256,
  64. feedforward_channels=2048,
  65. num_fcs=2,
  66. ffn_drop=0.,
  67. act_cfg=dict(type='PReLU'))),
  68. return_intermediate=True),
  69. positional_encoding=dict(num_feats=128, temperature=20, normalize=True),
  70. bbox_head=dict(
  71. type='DABDETRHead',
  72. num_classes=80,
  73. embed_dims=256,
  74. loss_cls=dict(
  75. type='FocalLoss',
  76. use_sigmoid=True,
  77. gamma=2.0,
  78. alpha=0.25,
  79. loss_weight=1.0),
  80. loss_bbox=dict(type='L1Loss', loss_weight=5.0),
  81. loss_iou=dict(type='GIoULoss', loss_weight=2.0)),
  82. # training and testing settings
  83. train_cfg=dict(
  84. assigner=dict(
  85. type='HungarianAssigner',
  86. match_costs=[
  87. dict(type='FocalLossCost', weight=2., eps=1e-8),
  88. dict(type='BBoxL1Cost', weight=5.0, box_format='xywh'),
  89. dict(type='IoUCost', iou_mode='giou', weight=2.0)
  90. ])),
  91. test_cfg=dict(max_per_img=300))
  92. # train_pipeline, NOTE the img_scale and the Pad's size_divisor is different
  93. # from the default setting in mmdet.
  94. train_pipeline = [
  95. dict(type='LoadImageFromFile', backend_args={{_base_.backend_args}}),
  96. dict(type='LoadAnnotations', with_bbox=True),
  97. dict(type='RandomFlip', prob=0.5),
  98. dict(
  99. type='RandomChoice',
  100. transforms=[[
  101. dict(
  102. type='RandomChoiceResize',
  103. scales=[(480, 1333), (512, 1333), (544, 1333), (576, 1333),
  104. (608, 1333), (640, 1333), (672, 1333), (704, 1333),
  105. (736, 1333), (768, 1333), (800, 1333)],
  106. keep_ratio=True)
  107. ],
  108. [
  109. dict(
  110. type='RandomChoiceResize',
  111. scales=[(400, 1333), (500, 1333), (600, 1333)],
  112. keep_ratio=True),
  113. dict(
  114. type='RandomCrop',
  115. crop_type='absolute_range',
  116. crop_size=(384, 600),
  117. allow_negative_crop=True),
  118. dict(
  119. type='RandomChoiceResize',
  120. scales=[(480, 1333), (512, 1333), (544, 1333),
  121. (576, 1333), (608, 1333), (640, 1333),
  122. (672, 1333), (704, 1333), (736, 1333),
  123. (768, 1333), (800, 1333)],
  124. keep_ratio=True)
  125. ]]),
  126. dict(type='PackDetInputs')
  127. ]
  128. train_dataloader = dict(dataset=dict(pipeline=train_pipeline))
  129. # optimizer
  130. optim_wrapper = dict(
  131. type='OptimWrapper',
  132. optimizer=dict(type='AdamW', lr=0.0001, weight_decay=0.0001),
  133. clip_grad=dict(max_norm=0.1, norm_type=2),
  134. paramwise_cfg=dict(
  135. custom_keys={'backbone': dict(lr_mult=0.1, decay_mult=1.0)}))
  136. # learning policy
  137. max_epochs = 50
  138. train_cfg = dict(
  139. type='EpochBasedTrainLoop', max_epochs=max_epochs, val_interval=1)
  140. val_cfg = dict(type='ValLoop')
  141. test_cfg = dict(type='TestLoop')
  142. param_scheduler = [
  143. dict(
  144. type='MultiStepLR',
  145. begin=0,
  146. end=max_epochs,
  147. by_epoch=True,
  148. milestones=[40],
  149. gamma=0.1)
  150. ]
  151. # NOTE: `auto_scale_lr` is for automatically scaling LR,
  152. # USER SHOULD NOT CHANGE ITS VALUES.
  153. # base_batch_size = (8 GPUs) x (2 samples per GPU)
  154. auto_scale_lr = dict(base_batch_size=16, enable=False)