yolov6_config.py 5.3 KB

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