rtcdet_config.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # yolo Config
  2. def build_rtcdet_config(args):
  3. if args.model == 'rtcdet_n':
  4. return RTCDetNConfig()
  5. elif args.model == 'rtcdet_t':
  6. return RTCDetTConfig()
  7. elif args.model == 'rtcdet_s':
  8. return RTCDetSConfig()
  9. elif args.model == 'rtcdet_m':
  10. return RTCDetMConfig()
  11. elif args.model == 'rtcdet_l':
  12. return RTCDetLConfig()
  13. elif args.model == 'rtcdet_x':
  14. return RTCDetXConfig()
  15. else:
  16. raise NotImplementedError("No config for model: {}".format(args.model))
  17. # RTCDet-Base config
  18. class RTCDetBaseConfig(object):
  19. def __init__(self) -> None:
  20. # ---------------- Model config ----------------
  21. self.width = 1.0
  22. self.depth = 1.0
  23. self.ratio = 1.0
  24. self.reg_max = 16
  25. self.out_stride = [8, 16, 32]
  26. self.max_stride = 32
  27. self.num_levels = 3
  28. self.scale = "b"
  29. ## Backbone
  30. self.bk_act = 'silu'
  31. self.bk_norm = 'BN'
  32. self.bk_depthwise = False
  33. self.use_pretrained = False
  34. ## Neck
  35. self.neck_act = 'silu'
  36. self.neck_norm = 'BN'
  37. self.neck_depthwise = False
  38. self.neck_expand_ratio = 0.5
  39. self.spp_pooling_size = 5
  40. ## FPN
  41. self.fpn_act = 'silu'
  42. self.fpn_norm = 'BN'
  43. self.fpn_depthwise = False
  44. ## Head
  45. self.head_act = 'silu'
  46. self.head_norm = 'BN'
  47. self.head_depthwise = False
  48. self.num_cls_head = 2
  49. self.num_reg_head = 2
  50. # ---------------- Post-process config ----------------
  51. ## Post process
  52. self.val_topk = 1000
  53. self.val_conf_thresh = 0.001
  54. self.val_nms_thresh = 0.7
  55. self.test_topk = 100
  56. self.test_conf_thresh = 0.3
  57. self.test_nms_thresh = 0.5
  58. # ---------------- Assignment config ----------------
  59. ## Matcher
  60. self.ota_soft_center_radius = 3.0
  61. self.ota_topk_candidates = 13
  62. ## Loss weight
  63. self.loss_cls = 1.0
  64. self.loss_box = 2.0
  65. self.loss_dfl = 0.5
  66. # ---------------- ModelEMA config ----------------
  67. self.use_ema = True
  68. self.ema_decay = 0.9998
  69. self.ema_tau = 2000
  70. # ---------------- Optimizer config ----------------
  71. self.trainer = 'yolo'
  72. self.optimizer = 'adamw'
  73. self.per_image_lr = 0.001 / 64
  74. self.base_lr = None # base_lr = per_image_lr * batch_size
  75. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  76. self.momentum = 0.9
  77. self.weight_decay = 0.05
  78. self.clip_max_norm = 35.0
  79. self.warmup_bias_lr = 0.1
  80. self.warmup_momentum = 0.8
  81. # ---------------- Lr Scheduler config ----------------
  82. self.warmup_epoch = 3
  83. self.lr_scheduler = "cosine"
  84. self.max_epoch = 300
  85. self.eval_epoch = 10
  86. self.no_aug_epoch = 20
  87. # ---------------- Data process config ----------------
  88. self.aug_type = 'yolo'
  89. self.box_format = 'xyxy'
  90. self.normalize_coords = False
  91. self.mosaic_prob = 0.0
  92. self.mixup_prob = 0.0
  93. self.copy_paste = 0.0 # approximated by the YOLOX's mixup
  94. self.multi_scale = [0.5, 1.25] # multi scale: [img_size * 0.5, img_size * 1.25]
  95. ## Pixel mean & std
  96. self.pixel_mean = [0., 0., 0.]
  97. self.pixel_std = [255., 255., 255.]
  98. ## Transforms
  99. self.train_img_size = 640
  100. self.test_img_size = 640
  101. self.use_ablu = True
  102. self.affine_params = {
  103. 'degrees': 0.0,
  104. 'translate': 0.2,
  105. 'scale': [0.1, 2.0],
  106. 'shear': 0.0,
  107. 'perspective': 0.0,
  108. 'hsv_h': 0.015,
  109. 'hsv_s': 0.7,
  110. 'hsv_v': 0.4,
  111. }
  112. def print_config(self):
  113. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  114. for k, v in config_dict.items():
  115. print("{} : {}".format(k, v))
  116. # RTCDet-N
  117. class RTCDetNConfig(RTCDetBaseConfig):
  118. def __init__(self) -> None:
  119. super().__init__()
  120. # ---------------- Model config ----------------
  121. self.width = 0.25
  122. self.depth = 0.34
  123. self.ratio = 2.0
  124. self.scale = "n"
  125. # ---------------- Data process config ----------------
  126. self.mosaic_prob = 1.0
  127. self.mixup_prob = 0.0
  128. self.copy_paste = 0.5
  129. # RTCDet-N
  130. class RTCDetTConfig(RTCDetBaseConfig):
  131. def __init__(self) -> None:
  132. super().__init__()
  133. # ---------------- Model config ----------------
  134. self.width = 0.375
  135. self.depth = 0.34
  136. self.ratio = 2.0
  137. self.scale = "t"
  138. # ---------------- Data process config ----------------
  139. self.mosaic_prob = 1.0
  140. self.mixup_prob = 0.0
  141. self.copy_paste = 0.5
  142. # RTCDet-S
  143. class RTCDetSConfig(RTCDetBaseConfig):
  144. def __init__(self) -> None:
  145. super().__init__()
  146. # ---------------- Model config ----------------
  147. self.width = 0.50
  148. self.depth = 0.34
  149. self.ratio = 2.0
  150. self.scale = "s"
  151. # ---------------- Data process config ----------------
  152. self.mosaic_prob = 1.0
  153. self.mixup_prob = 0.0
  154. self.copy_paste = 0.5
  155. # RTCDet-M
  156. class RTCDetMConfig(RTCDetBaseConfig):
  157. def __init__(self) -> None:
  158. super().__init__()
  159. # ---------------- Model config ----------------
  160. self.width = 0.75
  161. self.depth = 0.67
  162. self.ratio = 1.5
  163. self.scale = "m"
  164. # ---------------- Data process config ----------------
  165. self.mosaic_prob = 1.0
  166. self.mixup_prob = 0.1
  167. self.copy_paste = 0.5
  168. # RTCDet-L
  169. class RTCDetLConfig(RTCDetBaseConfig):
  170. def __init__(self) -> None:
  171. super().__init__()
  172. # ---------------- Model config ----------------
  173. self.width = 1.0
  174. self.depth = 1.0
  175. self.ratio = 1.0
  176. self.scale = "l"
  177. # ---------------- Data process config ----------------
  178. self.mosaic_prob = 1.0
  179. self.mixup_prob = 0.1
  180. self.copy_paste = 0.5
  181. # RTCDet-X
  182. class RTCDetXConfig(RTCDetBaseConfig):
  183. def __init__(self) -> None:
  184. super().__init__()
  185. # ---------------- Model config ----------------
  186. self.width = 1.25
  187. self.depth = 1.0
  188. self.ratio = 1.0
  189. self.scale = "x"
  190. # ---------------- Data process config ----------------
  191. self.mosaic_prob = 1.0
  192. self.mixup_prob = 0.1
  193. self.copy_paste = 0.5