ssdlite_mobilenetv2-scratch_8xb24-600e_coco.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. _base_ = [
  2. '../_base_/datasets/coco_detection.py',
  3. '../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
  4. ]
  5. # model settings
  6. data_preprocessor = dict(
  7. type='DetDataPreprocessor',
  8. mean=[123.675, 116.28, 103.53],
  9. std=[58.395, 57.12, 57.375],
  10. bgr_to_rgb=True,
  11. pad_size_divisor=1)
  12. model = dict(
  13. type='SingleStageDetector',
  14. data_preprocessor=data_preprocessor,
  15. backbone=dict(
  16. type='MobileNetV2',
  17. out_indices=(4, 7),
  18. norm_cfg=dict(type='BN', eps=0.001, momentum=0.03),
  19. init_cfg=dict(type='TruncNormal', layer='Conv2d', std=0.03)),
  20. neck=dict(
  21. type='SSDNeck',
  22. in_channels=(96, 1280),
  23. out_channels=(96, 1280, 512, 256, 256, 128),
  24. level_strides=(2, 2, 2, 2),
  25. level_paddings=(1, 1, 1, 1),
  26. l2_norm_scale=None,
  27. use_depthwise=True,
  28. norm_cfg=dict(type='BN', eps=0.001, momentum=0.03),
  29. act_cfg=dict(type='ReLU6'),
  30. init_cfg=dict(type='TruncNormal', layer='Conv2d', std=0.03)),
  31. bbox_head=dict(
  32. type='SSDHead',
  33. in_channels=(96, 1280, 512, 256, 256, 128),
  34. num_classes=80,
  35. use_depthwise=True,
  36. norm_cfg=dict(type='BN', eps=0.001, momentum=0.03),
  37. act_cfg=dict(type='ReLU6'),
  38. init_cfg=dict(type='Normal', layer='Conv2d', std=0.001),
  39. # set anchor size manually instead of using the predefined
  40. # SSD300 setting.
  41. anchor_generator=dict(
  42. type='SSDAnchorGenerator',
  43. scale_major=False,
  44. strides=[16, 32, 64, 107, 160, 320],
  45. ratios=[[2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]],
  46. min_sizes=[48, 100, 150, 202, 253, 304],
  47. max_sizes=[100, 150, 202, 253, 304, 320]),
  48. bbox_coder=dict(
  49. type='DeltaXYWHBBoxCoder',
  50. target_means=[.0, .0, .0, .0],
  51. target_stds=[0.1, 0.1, 0.2, 0.2])),
  52. # model training and testing settings
  53. train_cfg=dict(
  54. assigner=dict(
  55. type='MaxIoUAssigner',
  56. pos_iou_thr=0.5,
  57. neg_iou_thr=0.5,
  58. min_pos_iou=0.,
  59. ignore_iof_thr=-1,
  60. gt_max_assign_all=False),
  61. sampler=dict(type='PseudoSampler'),
  62. smoothl1_beta=1.,
  63. allowed_border=-1,
  64. pos_weight=-1,
  65. neg_pos_ratio=3,
  66. debug=False),
  67. test_cfg=dict(
  68. nms_pre=1000,
  69. nms=dict(type='nms', iou_threshold=0.45),
  70. min_bbox_size=0,
  71. score_thr=0.02,
  72. max_per_img=200))
  73. env_cfg = dict(cudnn_benchmark=True)
  74. # dataset settings
  75. input_size = 320
  76. train_pipeline = [
  77. dict(type='LoadImageFromFile'),
  78. dict(type='LoadAnnotations', with_bbox=True),
  79. dict(
  80. type='Expand',
  81. mean=data_preprocessor['mean'],
  82. to_rgb=data_preprocessor['bgr_to_rgb'],
  83. ratio_range=(1, 4)),
  84. dict(
  85. type='MinIoURandomCrop',
  86. min_ious=(0.1, 0.3, 0.5, 0.7, 0.9),
  87. min_crop_size=0.3),
  88. dict(type='Resize', scale=(input_size, input_size), keep_ratio=False),
  89. dict(type='RandomFlip', prob=0.5),
  90. dict(
  91. type='PhotoMetricDistortion',
  92. brightness_delta=32,
  93. contrast_range=(0.5, 1.5),
  94. saturation_range=(0.5, 1.5),
  95. hue_delta=18),
  96. dict(type='PackDetInputs')
  97. ]
  98. test_pipeline = [
  99. dict(type='LoadImageFromFile'),
  100. dict(type='Resize', scale=(input_size, input_size), keep_ratio=False),
  101. dict(type='LoadAnnotations', with_bbox=True),
  102. dict(
  103. type='PackDetInputs',
  104. meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
  105. 'scale_factor'))
  106. ]
  107. train_dataloader = dict(
  108. batch_size=24,
  109. num_workers=4,
  110. batch_sampler=None,
  111. dataset=dict(
  112. _delete_=True,
  113. type='RepeatDataset',
  114. times=5,
  115. dataset=dict(
  116. type={{_base_.dataset_type}},
  117. data_root={{_base_.data_root}},
  118. ann_file='annotations/instances_train2017.json',
  119. data_prefix=dict(img='train2017/'),
  120. filter_cfg=dict(filter_empty_gt=True, min_size=32),
  121. pipeline=train_pipeline)))
  122. val_dataloader = dict(batch_size=8, dataset=dict(pipeline=test_pipeline))
  123. test_dataloader = val_dataloader
  124. # training schedule
  125. max_epochs = 120
  126. train_cfg = dict(max_epochs=max_epochs, val_interval=5)
  127. # learning rate
  128. param_scheduler = [
  129. dict(
  130. type='LinearLR', start_factor=0.001, by_epoch=False, begin=0, end=500),
  131. dict(
  132. type='CosineAnnealingLR',
  133. begin=0,
  134. T_max=max_epochs,
  135. end=max_epochs,
  136. by_epoch=True,
  137. eta_min=0)
  138. ]
  139. # optimizer
  140. optim_wrapper = dict(
  141. type='OptimWrapper',
  142. optimizer=dict(type='SGD', lr=0.015, momentum=0.9, weight_decay=4.0e-5))
  143. custom_hooks = [
  144. dict(type='NumClassCheckHook'),
  145. dict(type='CheckInvalidLossHook', interval=50, priority='VERY_LOW')
  146. ]
  147. # NOTE: `auto_scale_lr` is for automatically scaling LR,
  148. # USER SHOULD NOT CHANGE ITS VALUES.
  149. # base_batch_size = (8 GPUs) x (24 samples per GPU)
  150. auto_scale_lr = dict(base_batch_size=192)