yolov8_e2e_config.py 6.0 KB

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