gelan_config.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.backbone = 'gelan_c'
  17. self.bk_act = 'silu'
  18. self.bk_norm = 'BN'
  19. self.bk_depthwise = False
  20. self.bk_down_pooling = True
  21. self.use_pretrained = True
  22. self.backbone_feats = {
  23. "c1": [64],
  24. "c2": [128, [128, 64], 256],
  25. "c3": [256, [256, 128], 512],
  26. "c4": [512, [512, 256], 512],
  27. "c5": [512, [512, 256], 512],
  28. }
  29. self.scale = "l"
  30. self.backbone_depth = 1
  31. ## Neck
  32. self.neck = 'spp_elan'
  33. self.neck_act = 'silu'
  34. self.neck_norm = 'BN'
  35. self.spp_pooling_size = 5
  36. self.spp_inter_dim = 256
  37. self.spp_out_dim = 512
  38. ## FPN
  39. self.fpn = 'gelan_pafpn'
  40. self.fpn_act = 'silu'
  41. self.fpn_norm = 'BN'
  42. self.fpn_depthwise = False
  43. self.fpn_down_pooling = True
  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.per_image_lr = 0.001 / 64
  85. self.base_lr = None # base_lr = per_image_lr * batch_size
  86. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  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 = 500
  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.use_ablu = True
  113. self.affine_params = {
  114. 'degrees': 0.0,
  115. 'translate': 0.2,
  116. 'scale': [0.1, 2.0],
  117. 'shear': 0.0,
  118. 'perspective': 0.0,
  119. 'hsv_h': 0.015,
  120. 'hsv_s': 0.7,
  121. 'hsv_v': 0.4,
  122. }
  123. def print_config(self):
  124. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  125. for k, v in config_dict.items():
  126. print("{} : {}".format(k, v))
  127. # GELAN-C
  128. class GElanCConfig(GElanBaseConfig):
  129. def __init__(self) -> None:
  130. super().__init__()
  131. self.backbone = 'gelan_c'
  132. self.use_pretrained = True
  133. self.scale = "l"
  134. # ---------------- Data process config ----------------
  135. self.mosaic_prob = 1.0
  136. self.mixup_prob = 0.1
  137. self.copy_paste = 0.5