gelan_config.py 4.5 KB

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