rtmdet.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import torch
  3. from mmengine.dist import get_world_size
  4. from mmengine.logging import print_log
  5. from mmdet.registry import MODELS
  6. from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig
  7. from .single_stage import SingleStageDetector
  8. @MODELS.register_module()
  9. class RTMDet(SingleStageDetector):
  10. """Implementation of RTMDet.
  11. Args:
  12. backbone (:obj:`ConfigDict` or dict): The backbone module.
  13. neck (:obj:`ConfigDict` or dict): The neck module.
  14. bbox_head (:obj:`ConfigDict` or dict): The bbox head module.
  15. train_cfg (:obj:`ConfigDict` or dict, optional): The training config
  16. of ATSS. Defaults to None.
  17. test_cfg (:obj:`ConfigDict` or dict, optional): The testing config
  18. of ATSS. Defaults to None.
  19. data_preprocessor (:obj:`ConfigDict` or dict, optional): Config of
  20. :class:`DetDataPreprocessor` to process the input data.
  21. Defaults to None.
  22. init_cfg (:obj:`ConfigDict` or dict, optional): the config to control
  23. the initialization. Defaults to None.
  24. use_syncbn (bool): Whether to use SyncBatchNorm. Defaults to True.
  25. """
  26. def __init__(self,
  27. backbone: ConfigType,
  28. neck: ConfigType,
  29. bbox_head: ConfigType,
  30. train_cfg: OptConfigType = None,
  31. test_cfg: OptConfigType = None,
  32. data_preprocessor: OptConfigType = None,
  33. init_cfg: OptMultiConfig = None,
  34. use_syncbn: bool = True) -> None:
  35. super().__init__(
  36. backbone=backbone,
  37. neck=neck,
  38. bbox_head=bbox_head,
  39. train_cfg=train_cfg,
  40. test_cfg=test_cfg,
  41. data_preprocessor=data_preprocessor,
  42. init_cfg=init_cfg)
  43. # TODO: Waiting for mmengine support
  44. if use_syncbn and get_world_size() > 1:
  45. torch.nn.SyncBatchNorm.convert_sync_batchnorm(self)
  46. print_log('Using SyncBatchNorm()', 'current')