yolof_config.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # Modified You Only Look One-level Feature
  2. def build_yolof_config(args):
  3. if args.model == 'yolof_n':
  4. return YolofNConfig()
  5. elif args.model == 'yolof_s':
  6. return YolofSConfig()
  7. elif args.model == 'yolof_m':
  8. return YolofMConfig()
  9. elif args.model == 'yolof_l':
  10. return YolofLConfig()
  11. else:
  12. raise NotImplementedError("No config for model: {}".format(args.model))
  13. # --------------- Base configuration ---------------
  14. class YolofBaseConfig(object):
  15. def __init__(self):
  16. # --------- Backbone ---------
  17. self.width = 1.0
  18. self.depth = 1.0
  19. self.ratio = 1.0
  20. self.scale = "b"
  21. self.max_stride = 32
  22. self.out_stride = 16
  23. ## Backbone
  24. self.bk_act = 'silu'
  25. self.bk_norm = 'BN'
  26. self.bk_depthwise = False
  27. self.use_pretrained = True
  28. # --------- Neck ---------
  29. self.upscale_factor = 2
  30. self.neck_dilations = [2, 4, 6, 8]
  31. self.neck_expand_ratio = 0.5
  32. self.neck_act = 'silu'
  33. self.neck_norm = 'BN'
  34. self.neck_depthwise = False
  35. # --------- Head ---------
  36. self.head_dim = 512
  37. self.num_cls_head = 4
  38. self.num_reg_head = 4
  39. self.head_act = 'silu'
  40. self.head_norm = 'BN'
  41. self.head_depthwise = False
  42. self.anchor_size = [[16, 16],
  43. [32, 32],
  44. [64, 64],
  45. [128, 128],
  46. [256, 256],
  47. [512, 512]]
  48. # --------- Post-process ---------
  49. ## Post process
  50. self.val_topk = 1000
  51. self.val_conf_thresh = 0.001
  52. self.val_nms_thresh = 0.7
  53. self.test_topk = 300
  54. self.test_conf_thresh = 0.4
  55. self.test_nms_thresh = 0.5
  56. # --------- Label Assignment ---------
  57. ## Matcher
  58. self.ota_soft_center_radius = 3.0
  59. self.ota_topk_candidates = 8
  60. ## Loss weight
  61. self.loss_cls = 1.0
  62. self.loss_box = 2.0
  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 = 300
  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.25] # multi scale: [img_size * 0.5, img_size * 1.25]
  92. ## Pixel mean & std
  93. self.pixel_mean = [123.675, 116.28, 103.53] # RGB format
  94. self.pixel_std = [58.395, 57.12, 57.375] # RGB format
  95. ## Transforms
  96. self.train_img_size = 640
  97. self.test_img_size = 640
  98. self.use_ablu = True
  99. self.affine_params = {
  100. 'degrees': 0.0,
  101. 'translate': 0.2,
  102. 'scale': [0.1, 2.0],
  103. 'shear': 0.0,
  104. 'perspective': 0.0,
  105. 'hsv_h': 0.015,
  106. 'hsv_s': 0.7,
  107. 'hsv_v': 0.4,
  108. }
  109. def print_config(self):
  110. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  111. for k, v in config_dict.items():
  112. print("{} : {}".format(k, v))
  113. # --------------- Modified YOLOF ---------------
  114. class YolofNConfig(YolofBaseConfig):
  115. def __init__(self) -> None:
  116. super().__init__()
  117. # ---------------- Model config ----------------
  118. self.width = 0.25
  119. self.depth = 0.34
  120. self.ratio = 2.0
  121. self.scale = "n"
  122. self.head_dim = 128
  123. # ---------------- Data process config ----------------
  124. self.mosaic_prob = 1.0
  125. self.mixup_prob = 0.0
  126. self.copy_paste = 0.5
  127. class YolofSConfig(YolofBaseConfig):
  128. def __init__(self) -> None:
  129. super().__init__()
  130. # ---------------- Model config ----------------
  131. self.width = 0.50
  132. self.depth = 0.34
  133. self.ratio = 2.0
  134. self.scale = "s"
  135. self.head_dim = 256
  136. # ---------------- Data process config ----------------
  137. self.mosaic_prob = 1.0
  138. self.mixup_prob = 0.0
  139. self.copy_paste = 0.5
  140. class YolofMConfig(YolofSConfig):
  141. def __init__(self) -> None:
  142. super().__init__()
  143. # ---------------- Model config ----------------
  144. self.width = 0.75
  145. self.depth = 0.67
  146. self.ratio = 1.5
  147. self.scale = "m"
  148. self.head_dim = 384
  149. # ---------------- Data process config ----------------
  150. self.mosaic_prob = 1.0
  151. self.mixup_prob = 0.1
  152. self.copy_paste = 0.5
  153. class YolofLConfig(YolofSConfig):
  154. def __init__(self) -> None:
  155. super().__init__()
  156. # ---------------- Model config ----------------
  157. self.width = 1.0
  158. self.depth = 1.0
  159. self.ratio = 1.0
  160. self.scale = "l"
  161. self.head_dim = 512
  162. # ---------------- Data process config ----------------
  163. self.mosaic_prob = 1.0
  164. self.mixup_prob = 0.1
  165. self.copy_paste = 0.5