ssdlite_mobilenetv2_scratch_600e_onehand.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # =========================================================
  2. # from 'mmdetection/configs/_base_/default_runtime.py'
  3. # =========================================================
  4. default_scope = 'mmdet'
  5. checkpoint_config = dict(interval=1)
  6. # yapf:disable
  7. log_config = dict(
  8. interval=50,
  9. hooks=[
  10. dict(type='TextLoggerHook'),
  11. # dict(type='TensorboardLoggerHook')
  12. ])
  13. # yapf:enable
  14. custom_hooks = [dict(type='NumClassCheckHook')]
  15. # =========================================================
  16. # model settings
  17. data_preprocessor = dict(
  18. type='DetDataPreprocessor',
  19. mean=[123.675, 116.28, 103.53],
  20. std=[58.395, 57.12, 57.375],
  21. bgr_to_rgb=True,
  22. pad_size_divisor=1)
  23. model = dict(
  24. type='SingleStageDetector',
  25. data_preprocessor=data_preprocessor,
  26. backbone=dict(
  27. type='MobileNetV2',
  28. out_indices=(4, 7),
  29. norm_cfg=dict(type='BN', eps=0.001, momentum=0.03),
  30. init_cfg=dict(type='TruncNormal', layer='Conv2d', std=0.03)),
  31. neck=dict(
  32. type='SSDNeck',
  33. in_channels=(96, 1280),
  34. out_channels=(96, 1280, 512, 256, 256, 128),
  35. level_strides=(2, 2, 2, 2),
  36. level_paddings=(1, 1, 1, 1),
  37. l2_norm_scale=None,
  38. use_depthwise=True,
  39. norm_cfg=dict(type='BN', eps=0.001, momentum=0.03),
  40. act_cfg=dict(type='ReLU6'),
  41. init_cfg=dict(type='TruncNormal', layer='Conv2d', std=0.03)),
  42. bbox_head=dict(
  43. type='SSDHead',
  44. in_channels=(96, 1280, 512, 256, 256, 128),
  45. num_classes=1,
  46. use_depthwise=True,
  47. norm_cfg=dict(type='BN', eps=0.001, momentum=0.03),
  48. act_cfg=dict(type='ReLU6'),
  49. init_cfg=dict(type='Normal', layer='Conv2d', std=0.001),
  50. # set anchor size manually instead of using the predefined
  51. # SSD300 setting.
  52. anchor_generator=dict(
  53. type='SSDAnchorGenerator',
  54. scale_major=False,
  55. strides=[16, 32, 64, 107, 160, 320],
  56. ratios=[[2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]],
  57. min_sizes=[48, 100, 150, 202, 253, 304],
  58. max_sizes=[100, 150, 202, 253, 304, 320]),
  59. bbox_coder=dict(
  60. type='DeltaXYWHBBoxCoder',
  61. target_means=[.0, .0, .0, .0],
  62. target_stds=[0.1, 0.1, 0.2, 0.2])),
  63. # model training and testing settings
  64. train_cfg=dict(
  65. assigner=dict(
  66. type='MaxIoUAssigner',
  67. pos_iou_thr=0.5,
  68. neg_iou_thr=0.5,
  69. min_pos_iou=0.,
  70. ignore_iof_thr=-1,
  71. gt_max_assign_all=False),
  72. sampler=dict(type='PseudoSampler'),
  73. smoothl1_beta=1.,
  74. allowed_border=-1,
  75. pos_weight=-1,
  76. neg_pos_ratio=3,
  77. debug=False),
  78. test_cfg=dict(
  79. nms_pre=1000,
  80. nms=dict(type='nms', iou_threshold=0.45),
  81. min_bbox_size=0,
  82. score_thr=0.02,
  83. max_per_img=200))
  84. cudnn_benchmark = True
  85. # dataset settings
  86. file_client_args = dict(backend='disk')
  87. dataset_type = 'CocoDataset'
  88. data_root = 'data/onehand10k/'
  89. classes = ('hand', )
  90. input_size = 320
  91. test_pipeline = [
  92. dict(type='LoadImageFromFile'),
  93. dict(type='Resize', scale=(input_size, input_size), keep_ratio=False),
  94. dict(type='LoadAnnotations', with_bbox=True),
  95. dict(
  96. type='PackDetInputs',
  97. meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
  98. 'scale_factor'))
  99. ]
  100. val_dataloader = dict(
  101. batch_size=8,
  102. num_workers=2,
  103. persistent_workers=True,
  104. drop_last=False,
  105. sampler=dict(type='DefaultSampler', shuffle=False),
  106. dataset=dict(
  107. type=dataset_type,
  108. data_root=data_root,
  109. ann_file='annotations/onehand10k_test.json',
  110. test_mode=True,
  111. pipeline=test_pipeline))
  112. test_dataloader = val_dataloader
  113. # optimizer
  114. optimizer = dict(type='SGD', lr=0.015, momentum=0.9, weight_decay=4.0e-5)
  115. optimizer_config = dict(grad_clip=None)
  116. # learning policy
  117. lr_config = dict(
  118. policy='CosineAnnealing',
  119. warmup='linear',
  120. warmup_iters=500,
  121. warmup_ratio=0.001,
  122. min_lr=0)
  123. runner = dict(type='EpochBasedRunner', max_epochs=120)
  124. # Avoid evaluation and saving weights too frequently
  125. evaluation = dict(interval=5, metric='bbox')
  126. checkpoint_config = dict(interval=5)
  127. custom_hooks = [
  128. dict(type='NumClassCheckHook'),
  129. dict(type='CheckInvalidLossHook', interval=50, priority='VERY_LOW')
  130. ]
  131. log_config = dict(interval=5)
  132. # NOTE: `auto_scale_lr` is for automatically scaling LR,
  133. # USER SHOULD NOT CHANGE ITS VALUES.
  134. # base_batch_size = (8 GPUs) x (24 samples per GPU)
  135. auto_scale_lr = dict(base_batch_size=192)
  136. load_from = 'https://download.openmmlab.com/mmdetection/'
  137. 'v2.0/ssd/ssdlite_mobilenetv2_scratch_600e_coco/'
  138. 'ssdlite_mobilenetv2_scratch_600e_coco_20210629_110627-974d9307.pth'
  139. vis_backends = [dict(type='LocalVisBackend')]
  140. visualizer = dict(
  141. type='DetLocalVisualizer', vis_backends=vis_backends, name='visualizer')