gelan_config.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # Gelan (proposed by yolov9) config
  2. def build_gelan_config(args):
  3. if args.model == 'gelan_s':
  4. return GElanSConfig()
  5. elif args.model == 'gelan_c':
  6. return GElanCConfig()
  7. else:
  8. raise NotImplementedError("No config for model: {}".format(args.model))
  9. # GELAN-Base config
  10. class GElanBaseConfig(object):
  11. def __init__(self) -> None:
  12. # ---------------- Model config ----------------
  13. self.reg_max = 16
  14. self.out_stride = [8, 16, 32]
  15. self.max_stride = 32
  16. self.num_levels = 3
  17. ## Backbone
  18. self.backbone = 'gelan'
  19. self.bk_act = 'silu'
  20. self.bk_norm = 'BN'
  21. self.bk_depthwise = False
  22. self.use_pretrained = True
  23. self.backbone_feats = {
  24. "c1": [64],
  25. "c2": [128, [128, 64], 256],
  26. "c3": [256, [256, 128], 512],
  27. "c4": [512, [512, 256], 512],
  28. "c5": [512, [512, 256], 512],
  29. }
  30. self.scale = "l"
  31. self.backbone_depth = 1
  32. ## Neck
  33. self.neck = 'spp_elan'
  34. self.neck_act = 'silu'
  35. self.neck_norm = 'BN'
  36. self.spp_pooling_size = 5
  37. self.spp_inter_dim = 256
  38. self.spp_out_dim = 512
  39. ## FPN
  40. self.fpn = 'gelan_pafpn'
  41. self.fpn_act = 'silu'
  42. self.fpn_norm = 'BN'
  43. self.fpn_depthwise = False
  44. self.fpn_depth = 1
  45. self.fpn_feats_td = {
  46. "p4": [[512, 256], 512],
  47. "p3": [[256, 128], 256],
  48. }
  49. self.fpn_feats_bu = {
  50. "p4": [[512, 256], 512],
  51. "p5": [[512, 256], 512],
  52. }
  53. ## Head
  54. self.head = 'gelan_head'
  55. self.head_act = 'silu'
  56. self.head_norm = 'BN'
  57. self.head_depthwise = False
  58. self.num_cls_head = 2
  59. self.num_reg_head = 2
  60. # ---------------- Post-process config ----------------
  61. ## Post process
  62. self.val_topk = 1000
  63. self.val_conf_thresh = 0.001
  64. self.val_nms_thresh = 0.7
  65. self.test_topk = 100
  66. self.test_conf_thresh = 0.2
  67. self.test_nms_thresh = 0.5
  68. # ---------------- Assignment config ----------------
  69. ## Matcher
  70. self.tal_topk_candidates = 10
  71. self.tal_alpha = 0.5
  72. self.tal_beta = 6.0
  73. ## Loss weight
  74. self.loss_cls = 0.5
  75. self.loss_box = 7.5
  76. self.loss_dfl = 1.5
  77. # ---------------- ModelEMA config ----------------
  78. self.use_ema = True
  79. self.ema_decay = 0.9998
  80. self.ema_tau = 2000
  81. # ---------------- Optimizer config ----------------
  82. self.trainer = 'yolo'
  83. self.optimizer = 'adamw'
  84. self.base_lr = 0.001 # base_lr = per_image_lr * batch_size
  85. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  86. self.batch_size_base = 64
  87. self.momentum = 0.9
  88. self.weight_decay = 0.05
  89. self.clip_max_norm = 35.0
  90. self.warmup_bias_lr = 0.1
  91. self.warmup_momentum = 0.8
  92. # ---------------- Lr Scheduler config ----------------
  93. self.warmup_epoch = 3
  94. self.lr_scheduler = "cosine"
  95. self.max_epoch = 300
  96. self.eval_epoch = 10
  97. self.no_aug_epoch = 20
  98. # ---------------- Data process config ----------------
  99. self.aug_type = 'yolo'
  100. self.box_format = 'xyxy'
  101. self.normalize_coords = False
  102. self.mosaic_prob = 0.0
  103. self.mixup_prob = 0.0
  104. self.copy_paste = 0.0 # approximated by the YOLOX's mixup
  105. self.multi_scale = [0.5, 1.25] # multi scale: [img_size * 0.5, img_size * 1.25]
  106. ## Pixel mean & std
  107. self.pixel_mean = [0., 0., 0.]
  108. self.pixel_std = [255., 255., 255.]
  109. ## Transforms
  110. self.train_img_size = 640
  111. self.test_img_size = 640
  112. self.affine_params = {
  113. 'degrees': 0.0,
  114. 'translate': 0.2,
  115. 'scale': [0.1, 2.0],
  116. 'shear': 0.0,
  117. 'perspective': 0.0,
  118. 'hsv_h': 0.015,
  119. 'hsv_s': 0.7,
  120. 'hsv_v': 0.4,
  121. }
  122. def print_config(self):
  123. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  124. for k, v in config_dict.items():
  125. print("{} : {}".format(k, v))
  126. # GELAN-C
  127. class GElanCConfig(GElanBaseConfig):
  128. def __init__(self) -> None:
  129. super().__init__()
  130. self.backbone = 'gelan'
  131. self.use_pretrained = True
  132. self.scale = "c"
  133. # ---------------- Data process config ----------------
  134. self.mosaic_prob = 1.0
  135. self.mixup_prob = 0.1
  136. self.copy_paste = 0.5
  137. # GELAN-S
  138. class GElanSConfig(GElanBaseConfig):
  139. def __init__(self) -> None:
  140. super().__init__()
  141. # ---------------- Model config ----------------
  142. ## Backbone
  143. self.backbone = 'gelan'
  144. self.use_pretrained = True
  145. self.backbone_feats = {
  146. "c1": [32],
  147. "c2": [64, [64, 32], 64],
  148. "c3": [64, [64, 32], 128],
  149. "c4": [128, [128, 64], 256],
  150. "c5": [256, [256, 128], 256],
  151. }
  152. self.scale = "s"
  153. self.backbone_depth = 3
  154. ## Neck
  155. self.spp_inter_dim = 128
  156. self.spp_out_dim = 256
  157. ## FPN
  158. self.fpn_depth = 3
  159. self.fpn_feats_td = {
  160. "p4": [[256, 128], 256],
  161. "p3": [[128, 64], 128],
  162. }
  163. self.fpn_feats_bu = {
  164. "p4": [[256, 128], 256],
  165. "p5": [[256, 128], 256],
  166. }
  167. # ---------------- Data process config ----------------
  168. self.mosaic_prob = 1.0
  169. self.mixup_prob = 0.0
  170. self.copy_paste = 0.5 # approximated by the YOLOX's mixup
  171. def print_config(self):
  172. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  173. for k, v in config_dict.items():
  174. print("{} : {}".format(k, v))