detic_centernet2_swin-b_fpn_4x_lvis-coco-in21k.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. _base_ = 'mmdet::common/lsj-200e_coco-detection.py'
  2. custom_imports = dict(
  3. imports=['projects.Detic.detic'], allow_failed_imports=False)
  4. image_size = (1024, 1024)
  5. batch_augments = [dict(type='BatchFixedSizePad', size=image_size)]
  6. cls_layer = dict(
  7. type='ZeroShotClassifier',
  8. zs_weight_path='rand',
  9. zs_weight_dim=512,
  10. use_bias=0.0,
  11. norm_weight=True,
  12. norm_temperature=50.0)
  13. reg_layer = [
  14. dict(type='Linear', in_features=1024, out_features=1024),
  15. dict(type='ReLU', inplace=True),
  16. dict(type='Linear', in_features=1024, out_features=4)
  17. ]
  18. num_classes = 22047
  19. model = dict(
  20. type='CascadeRCNN',
  21. data_preprocessor=dict(
  22. type='DetDataPreprocessor',
  23. mean=[123.675, 116.28, 103.53],
  24. std=[58.395, 57.12, 57.375],
  25. bgr_to_rgb=True,
  26. pad_size_divisor=32,
  27. batch_augments=batch_augments),
  28. backbone=dict(
  29. type='SwinTransformer',
  30. embed_dims=128,
  31. depths=[2, 2, 18, 2],
  32. num_heads=[4, 8, 16, 32],
  33. window_size=7,
  34. mlp_ratio=4,
  35. qkv_bias=True,
  36. qk_scale=None,
  37. drop_rate=0.,
  38. attn_drop_rate=0.,
  39. drop_path_rate=0.3,
  40. patch_norm=True,
  41. out_indices=(1, 2, 3),
  42. with_cp=False),
  43. neck=dict(
  44. type='FPN',
  45. in_channels=[256, 512, 1024],
  46. out_channels=256,
  47. start_level=0,
  48. add_extra_convs='on_output',
  49. num_outs=5,
  50. init_cfg=dict(type='Caffe2Xavier', layer='Conv2d'),
  51. relu_before_extra_convs=True),
  52. rpn_head=dict(
  53. type='CenterNetRPNHead',
  54. num_classes=1,
  55. in_channels=256,
  56. stacked_convs=4,
  57. feat_channels=256,
  58. strides=[8, 16, 32, 64, 128],
  59. conv_bias=True,
  60. norm_cfg=dict(type='GN', num_groups=32, requires_grad=True),
  61. loss_cls=dict(
  62. type='GaussianFocalLoss',
  63. pos_weight=0.25,
  64. neg_weight=0.75,
  65. loss_weight=1.0),
  66. loss_bbox=dict(type='GIoULoss', loss_weight=2.0),
  67. ),
  68. roi_head=dict(
  69. type='DeticRoIHead',
  70. num_stages=3,
  71. stage_loss_weights=[1, 0.5, 0.25],
  72. bbox_roi_extractor=dict(
  73. type='SingleRoIExtractor',
  74. roi_layer=dict(
  75. type='RoIAlign',
  76. output_size=7,
  77. sampling_ratio=0,
  78. use_torchvision=True),
  79. out_channels=256,
  80. featmap_strides=[8, 16, 32],
  81. # approximately equal to
  82. # canonical_box_size=224, canonical_level=4 in D2
  83. finest_scale=112),
  84. bbox_head=[
  85. dict(
  86. type='DeticBBoxHead',
  87. in_channels=256,
  88. fc_out_channels=1024,
  89. roi_feat_size=7,
  90. num_classes=num_classes,
  91. cls_predictor_cfg=cls_layer,
  92. reg_predictor_cfg=reg_layer,
  93. bbox_coder=dict(
  94. type='DeltaXYWHBBoxCoder',
  95. target_means=[0., 0., 0., 0.],
  96. target_stds=[0.1, 0.1, 0.2, 0.2]),
  97. reg_class_agnostic=True,
  98. loss_cls=dict(
  99. type='CrossEntropyLoss', use_sigmoid=True,
  100. loss_weight=1.0),
  101. loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
  102. loss_weight=1.0)),
  103. dict(
  104. type='DeticBBoxHead',
  105. in_channels=256,
  106. fc_out_channels=1024,
  107. roi_feat_size=7,
  108. num_classes=num_classes,
  109. cls_predictor_cfg=cls_layer,
  110. reg_predictor_cfg=reg_layer,
  111. bbox_coder=dict(
  112. type='DeltaXYWHBBoxCoder',
  113. target_means=[0., 0., 0., 0.],
  114. target_stds=[0.05, 0.05, 0.1, 0.1]),
  115. reg_class_agnostic=True,
  116. loss_cls=dict(
  117. type='CrossEntropyLoss', use_sigmoid=True,
  118. loss_weight=1.0),
  119. loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
  120. loss_weight=1.0)),
  121. dict(
  122. type='DeticBBoxHead',
  123. in_channels=256,
  124. fc_out_channels=1024,
  125. roi_feat_size=7,
  126. num_classes=num_classes,
  127. cls_predictor_cfg=cls_layer,
  128. reg_predictor_cfg=reg_layer,
  129. bbox_coder=dict(
  130. type='DeltaXYWHBBoxCoder',
  131. target_means=[0., 0., 0., 0.],
  132. target_stds=[0.033, 0.033, 0.067, 0.067]),
  133. reg_class_agnostic=True,
  134. loss_cls=dict(
  135. type='CrossEntropyLoss', use_sigmoid=True,
  136. loss_weight=1.0),
  137. loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0))
  138. ],
  139. mask_roi_extractor=dict(
  140. type='SingleRoIExtractor',
  141. roi_layer=dict(type='RoIAlign', output_size=14, sampling_ratio=0),
  142. out_channels=256,
  143. featmap_strides=[8, 16, 32],
  144. # approximately equal to
  145. # canonical_box_size=224, canonical_level=4 in D2
  146. finest_scale=112),
  147. mask_head=dict(
  148. type='FCNMaskHead',
  149. num_convs=4,
  150. in_channels=256,
  151. conv_out_channels=256,
  152. class_agnostic=True,
  153. num_classes=num_classes,
  154. loss_mask=dict(
  155. type='CrossEntropyLoss', use_mask=True, loss_weight=1.0))),
  156. # model training and testing settings
  157. train_cfg=dict(
  158. rpn=dict(
  159. assigner=dict(
  160. type='MaxIoUAssigner',
  161. pos_iou_thr=0.7,
  162. neg_iou_thr=0.3,
  163. min_pos_iou=0.3,
  164. match_low_quality=True,
  165. ignore_iof_thr=-1),
  166. sampler=dict(
  167. type='RandomSampler',
  168. num=256,
  169. pos_fraction=0.5,
  170. neg_pos_ub=-1,
  171. add_gt_as_proposals=False),
  172. allowed_border=0,
  173. pos_weight=-1,
  174. debug=False),
  175. rpn_proposal=dict(
  176. nms_pre=2000,
  177. max_per_img=2000,
  178. nms=dict(type='nms', iou_threshold=0.7),
  179. min_bbox_size=0),
  180. rcnn=[
  181. dict(
  182. assigner=dict(
  183. type='MaxIoUAssigner',
  184. pos_iou_thr=0.6,
  185. neg_iou_thr=0.6,
  186. min_pos_iou=0.6,
  187. match_low_quality=False,
  188. ignore_iof_thr=-1),
  189. sampler=dict(
  190. type='RandomSampler',
  191. num=512,
  192. pos_fraction=0.25,
  193. neg_pos_ub=-1,
  194. add_gt_as_proposals=True),
  195. mask_size=28,
  196. pos_weight=-1,
  197. debug=False),
  198. dict(
  199. assigner=dict(
  200. type='MaxIoUAssigner',
  201. pos_iou_thr=0.7,
  202. neg_iou_thr=0.7,
  203. min_pos_iou=0.7,
  204. match_low_quality=False,
  205. ignore_iof_thr=-1),
  206. sampler=dict(
  207. type='RandomSampler',
  208. num=512,
  209. pos_fraction=0.25,
  210. neg_pos_ub=-1,
  211. add_gt_as_proposals=True),
  212. mask_size=28,
  213. pos_weight=-1,
  214. debug=False),
  215. dict(
  216. assigner=dict(
  217. type='MaxIoUAssigner',
  218. pos_iou_thr=0.8,
  219. neg_iou_thr=0.8,
  220. min_pos_iou=0.8,
  221. match_low_quality=False,
  222. ignore_iof_thr=-1),
  223. sampler=dict(
  224. type='RandomSampler',
  225. num=512,
  226. pos_fraction=0.25,
  227. neg_pos_ub=-1,
  228. add_gt_as_proposals=True),
  229. mask_size=28,
  230. pos_weight=-1,
  231. debug=False)
  232. ]),
  233. test_cfg=dict(
  234. rpn=dict(
  235. score_thr=0.0001,
  236. nms_pre=1000,
  237. max_per_img=256,
  238. nms=dict(type='nms', iou_threshold=0.9),
  239. min_bbox_size=0),
  240. rcnn=dict(
  241. score_thr=0.02,
  242. nms=dict(type='nms', iou_threshold=0.5),
  243. max_per_img=300,
  244. mask_thr_binary=0.5)))
  245. backend = 'pillow'
  246. test_pipeline = [
  247. dict(
  248. type='LoadImageFromFile',
  249. backend_args=_base_.backend_args,
  250. imdecode_backend=backend),
  251. dict(type='Resize', scale=(1333, 800), keep_ratio=True, backend=backend),
  252. dict(
  253. type='LoadAnnotations',
  254. with_bbox=True,
  255. with_mask=True,
  256. poly2mask=False),
  257. dict(
  258. type='PackDetInputs',
  259. meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
  260. 'scale_factor'))
  261. ]
  262. train_dataloader = dict(batch_size=8, num_workers=4)
  263. val_dataloader = dict(dataset=dict(pipeline=test_pipeline))
  264. test_dataloader = val_dataloader
  265. # Enable automatic-mixed-precision training with AmpOptimWrapper.
  266. optim_wrapper = dict(
  267. type='AmpOptimWrapper',
  268. optimizer=dict(
  269. type='SGD', lr=0.01 * 4, momentum=0.9, weight_decay=0.00004),
  270. paramwise_cfg=dict(norm_decay_mult=0.))
  271. param_scheduler = [
  272. dict(
  273. type='LinearLR',
  274. start_factor=0.00025,
  275. by_epoch=False,
  276. begin=0,
  277. end=4000),
  278. dict(
  279. type='MultiStepLR',
  280. begin=0,
  281. end=25,
  282. by_epoch=True,
  283. milestones=[22, 24],
  284. gamma=0.1)
  285. ]
  286. # NOTE: `auto_scale_lr` is for automatically scaling LR,
  287. # USER SHOULD NOT CHANGE ITS VALUES.
  288. # base_batch_size = (8 GPUs) x (8 samples per GPU)
  289. auto_scale_lr = dict(base_batch_size=64)