registry.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. """MMDetection provides 17 registry nodes to support using modules across
  3. projects. Each node is a child of the root registry in MMEngine.
  4. More details can be found at
  5. https://mmengine.readthedocs.io/en/latest/tutorials/registry.html.
  6. """
  7. from mmengine.registry import DATA_SAMPLERS as MMENGINE_DATA_SAMPLERS
  8. from mmengine.registry import DATASETS as MMENGINE_DATASETS
  9. from mmengine.registry import EVALUATOR as MMENGINE_EVALUATOR
  10. from mmengine.registry import HOOKS as MMENGINE_HOOKS
  11. from mmengine.registry import LOG_PROCESSORS as MMENGINE_LOG_PROCESSORS
  12. from mmengine.registry import LOOPS as MMENGINE_LOOPS
  13. from mmengine.registry import METRICS as MMENGINE_METRICS
  14. from mmengine.registry import MODEL_WRAPPERS as MMENGINE_MODEL_WRAPPERS
  15. from mmengine.registry import MODELS as MMENGINE_MODELS
  16. from mmengine.registry import \
  17. OPTIM_WRAPPER_CONSTRUCTORS as MMENGINE_OPTIM_WRAPPER_CONSTRUCTORS
  18. from mmengine.registry import OPTIM_WRAPPERS as MMENGINE_OPTIM_WRAPPERS
  19. from mmengine.registry import OPTIMIZERS as MMENGINE_OPTIMIZERS
  20. from mmengine.registry import PARAM_SCHEDULERS as MMENGINE_PARAM_SCHEDULERS
  21. from mmengine.registry import \
  22. RUNNER_CONSTRUCTORS as MMENGINE_RUNNER_CONSTRUCTORS
  23. from mmengine.registry import RUNNERS as MMENGINE_RUNNERS
  24. from mmengine.registry import TASK_UTILS as MMENGINE_TASK_UTILS
  25. from mmengine.registry import TRANSFORMS as MMENGINE_TRANSFORMS
  26. from mmengine.registry import VISBACKENDS as MMENGINE_VISBACKENDS
  27. from mmengine.registry import VISUALIZERS as MMENGINE_VISUALIZERS
  28. from mmengine.registry import \
  29. WEIGHT_INITIALIZERS as MMENGINE_WEIGHT_INITIALIZERS
  30. from mmengine.registry import Registry
  31. # manage all kinds of runners like `EpochBasedRunner` and `IterBasedRunner`
  32. RUNNERS = Registry(
  33. 'runner', parent=MMENGINE_RUNNERS, locations=['mmdet.engine.runner'])
  34. # manage runner constructors that define how to initialize runners
  35. RUNNER_CONSTRUCTORS = Registry(
  36. 'runner constructor',
  37. parent=MMENGINE_RUNNER_CONSTRUCTORS,
  38. locations=['mmdet.engine.runner'])
  39. # manage all kinds of loops like `EpochBasedTrainLoop`
  40. LOOPS = Registry(
  41. 'loop', parent=MMENGINE_LOOPS, locations=['mmdet.engine.runner'])
  42. # manage all kinds of hooks like `CheckpointHook`
  43. HOOKS = Registry(
  44. 'hook', parent=MMENGINE_HOOKS, locations=['mmdet.engine.hooks'])
  45. # manage data-related modules
  46. DATASETS = Registry(
  47. 'dataset', parent=MMENGINE_DATASETS, locations=['mmdet.datasets'])
  48. DATA_SAMPLERS = Registry(
  49. 'data sampler',
  50. parent=MMENGINE_DATA_SAMPLERS,
  51. locations=['mmdet.datasets.samplers'])
  52. TRANSFORMS = Registry(
  53. 'transform',
  54. parent=MMENGINE_TRANSFORMS,
  55. locations=['mmdet.datasets.transforms'])
  56. # manage all kinds of modules inheriting `nn.Module`
  57. MODELS = Registry('model', parent=MMENGINE_MODELS, locations=['mmdet.models'])
  58. # manage all kinds of model wrappers like 'MMDistributedDataParallel'
  59. MODEL_WRAPPERS = Registry(
  60. 'model_wrapper',
  61. parent=MMENGINE_MODEL_WRAPPERS,
  62. locations=['mmdet.models'])
  63. # manage all kinds of weight initialization modules like `Uniform`
  64. WEIGHT_INITIALIZERS = Registry(
  65. 'weight initializer',
  66. parent=MMENGINE_WEIGHT_INITIALIZERS,
  67. locations=['mmdet.models'])
  68. # manage all kinds of optimizers like `SGD` and `Adam`
  69. OPTIMIZERS = Registry(
  70. 'optimizer',
  71. parent=MMENGINE_OPTIMIZERS,
  72. locations=['mmdet.engine.optimizers'])
  73. # manage optimizer wrapper
  74. OPTIM_WRAPPERS = Registry(
  75. 'optim_wrapper',
  76. parent=MMENGINE_OPTIM_WRAPPERS,
  77. locations=['mmdet.engine.optimizers'])
  78. # manage constructors that customize the optimization hyperparameters.
  79. OPTIM_WRAPPER_CONSTRUCTORS = Registry(
  80. 'optimizer constructor',
  81. parent=MMENGINE_OPTIM_WRAPPER_CONSTRUCTORS,
  82. locations=['mmdet.engine.optimizers'])
  83. # manage all kinds of parameter schedulers like `MultiStepLR`
  84. PARAM_SCHEDULERS = Registry(
  85. 'parameter scheduler',
  86. parent=MMENGINE_PARAM_SCHEDULERS,
  87. locations=['mmdet.engine.schedulers'])
  88. # manage all kinds of metrics
  89. METRICS = Registry(
  90. 'metric', parent=MMENGINE_METRICS, locations=['mmdet.evaluation'])
  91. # manage evaluator
  92. EVALUATOR = Registry(
  93. 'evaluator', parent=MMENGINE_EVALUATOR, locations=['mmdet.evaluation'])
  94. # manage task-specific modules like anchor generators and box coders
  95. TASK_UTILS = Registry(
  96. 'task util', parent=MMENGINE_TASK_UTILS, locations=['mmdet.models'])
  97. # manage visualizer
  98. VISUALIZERS = Registry(
  99. 'visualizer',
  100. parent=MMENGINE_VISUALIZERS,
  101. locations=['mmdet.visualization'])
  102. # manage visualizer backend
  103. VISBACKENDS = Registry(
  104. 'vis_backend',
  105. parent=MMENGINE_VISBACKENDS,
  106. locations=['mmdet.visualization'])
  107. # manage logprocessor
  108. LOG_PROCESSORS = Registry(
  109. 'log_processor',
  110. parent=MMENGINE_LOG_PROCESSORS,
  111. # TODO: update the location when mmdet has its own log processor
  112. locations=['mmdet.engine'])