ms_3x_coco.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. _base_ = '../_base_/default_runtime.py'
  2. # dataset settings
  3. dataset_type = 'CocoDataset'
  4. data_root = 'data/coco/'
  5. # Example to use different file client
  6. # Method 1: simply set the data root and let the file I/O module
  7. # automatically infer from prefix (not support LMDB and Memcache yet)
  8. # data_root = 's3://openmmlab/datasets/detection/coco/'
  9. # Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6
  10. # backend_args = dict(
  11. # backend='petrel',
  12. # path_mapping=dict({
  13. # './data/': 's3://openmmlab/datasets/detection/',
  14. # 'data/': 's3://openmmlab/datasets/detection/'
  15. # }))
  16. backend_args = None
  17. train_pipeline = [
  18. dict(type='LoadImageFromFile', backend_args=backend_args),
  19. dict(type='LoadAnnotations', with_bbox=True),
  20. dict(
  21. type='RandomResize', scale=[(1333, 640), (1333, 800)],
  22. keep_ratio=True),
  23. dict(type='RandomFlip', prob=0.5),
  24. dict(type='PackDetInputs')
  25. ]
  26. test_pipeline = [
  27. dict(type='LoadImageFromFile', backend_args=backend_args),
  28. dict(type='Resize', scale=(1333, 800), keep_ratio=True),
  29. dict(type='LoadAnnotations', with_bbox=True),
  30. dict(
  31. type='PackDetInputs',
  32. meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
  33. 'scale_factor'))
  34. ]
  35. train_dataloader = dict(
  36. batch_size=2,
  37. num_workers=2,
  38. persistent_workers=True,
  39. sampler=dict(type='DefaultSampler', shuffle=True),
  40. batch_sampler=dict(type='AspectRatioBatchSampler'),
  41. dataset=dict(
  42. type='RepeatDataset',
  43. times=3,
  44. dataset=dict(
  45. type=dataset_type,
  46. data_root=data_root,
  47. ann_file='annotations/instances_train2017.json',
  48. data_prefix=dict(img='train2017/'),
  49. filter_cfg=dict(filter_empty_gt=True, min_size=32),
  50. pipeline=train_pipeline,
  51. backend_args=backend_args)))
  52. val_dataloader = dict(
  53. batch_size=1,
  54. num_workers=2,
  55. persistent_workers=True,
  56. drop_last=False,
  57. sampler=dict(type='DefaultSampler', shuffle=False),
  58. dataset=dict(
  59. type=dataset_type,
  60. data_root=data_root,
  61. ann_file='annotations/instances_val2017.json',
  62. data_prefix=dict(img='val2017/'),
  63. test_mode=True,
  64. pipeline=test_pipeline,
  65. backend_args=backend_args))
  66. test_dataloader = val_dataloader
  67. val_evaluator = dict(
  68. type='CocoMetric',
  69. ann_file=data_root + 'annotations/instances_val2017.json',
  70. metric='bbox',
  71. backend_args=backend_args)
  72. test_evaluator = val_evaluator
  73. # training schedule for 3x with `RepeatDataset`
  74. train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=12, val_interval=1)
  75. val_cfg = dict(type='ValLoop')
  76. test_cfg = dict(type='TestLoop')
  77. # learning rate
  78. # Experiments show that using milestones=[9, 11] has higher performance
  79. param_scheduler = [
  80. dict(
  81. type='LinearLR', start_factor=0.001, by_epoch=False, begin=0, end=500),
  82. dict(
  83. type='MultiStepLR',
  84. begin=0,
  85. end=12,
  86. by_epoch=True,
  87. milestones=[9, 11],
  88. gamma=0.1)
  89. ]
  90. # optimizer
  91. optim_wrapper = dict(
  92. type='OptimWrapper',
  93. optimizer=dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001))
  94. # Default setting for scaling LR automatically
  95. # - `enable` means enable scaling LR automatically
  96. # or not by default.
  97. # - `base_batch_size` = (8 GPUs) x (2 samples per GPU).
  98. auto_scale_lr = dict(enable=False, base_batch_size=16)