yolov5_af_config.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # yolo Config
  2. def build_yolov5af_config(args):
  3. if args.model == 'yolov5_af_s':
  4. return Yolov5AFSConfig()
  5. else:
  6. raise NotImplementedError("No config for model: {}".format(args.model))
  7. # YOLOv5AF-Base config
  8. class Yolov5AFBaseConfig(object):
  9. def __init__(self) -> None:
  10. # ---------------- Model config ----------------
  11. self.width = 1.0
  12. self.depth = 1.0
  13. self.out_stride = [8, 16, 32]
  14. self.max_stride = 32
  15. self.num_levels = 3
  16. self.scale = "b"
  17. ## Backbone
  18. self.bk_act = 'silu'
  19. self.bk_norm = 'BN'
  20. self.bk_depthwise = False
  21. ## Neck
  22. self.neck_act = 'silu'
  23. self.neck_norm = 'BN'
  24. self.neck_depthwise = False
  25. self.neck_expand_ratio = 0.5
  26. self.spp_pooling_size = 5
  27. ## FPN
  28. self.fpn_act = 'silu'
  29. self.fpn_norm = 'BN'
  30. self.fpn_depthwise = False
  31. ## Head
  32. self.head_act = 'silu'
  33. self.head_norm = 'BN'
  34. self.head_depthwise = False
  35. self.head_dim = 256
  36. self.num_cls_head = 2
  37. self.num_reg_head = 2
  38. # ---------------- Post-process config ----------------
  39. ## Post process
  40. self.val_topk = 1000
  41. self.val_conf_thresh = 0.001
  42. self.val_nms_thresh = 0.7
  43. self.test_topk = 100
  44. self.test_conf_thresh = 0.2
  45. self.test_nms_thresh = 0.5
  46. # ---------------- Assignment config ----------------
  47. ## Matcher
  48. self.ota_center_sampling_radius = 2.5
  49. self.ota_topk_candidate = 10
  50. ## Loss weight
  51. self.loss_obj = 1.0
  52. self.loss_cls = 1.0
  53. self.loss_box = 5.0
  54. # ---------------- ModelEMA config ----------------
  55. self.use_ema = True
  56. self.ema_decay = 0.9998
  57. self.ema_tau = 2000
  58. # ---------------- Optimizer config ----------------
  59. self.trainer = 'yolo'
  60. self.optimizer = 'adamw'
  61. self.per_image_lr = 0.001 / 64
  62. self.base_lr = None # base_lr = per_image_lr * batch_size
  63. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  64. self.momentum = 0.9
  65. self.weight_decay = 0.05
  66. self.clip_max_norm = -1.
  67. self.warmup_bias_lr = 0.1
  68. self.warmup_momentum = 0.8
  69. # ---------------- Lr Scheduler config ----------------
  70. self.warmup_epoch = 3
  71. self.lr_scheduler = "cosine"
  72. self.max_epoch = 300
  73. self.eval_epoch = 10
  74. self.no_aug_epoch = 20
  75. # ---------------- Data process config ----------------
  76. self.aug_type = 'yolo'
  77. self.box_format = 'xyxy'
  78. self.normalize_coords = False
  79. self.mosaic_prob = 1.0
  80. self.mixup_prob = 0.0
  81. self.copy_paste = 0.0 # approximated by the YOLOX's mixup
  82. self.multi_scale = [0.5, 1.25] # multi scale: [img_size * 0.5, img_size * 1.25]
  83. ## Pixel mean & std
  84. self.pixel_mean = [0., 0., 0.]
  85. self.pixel_std = [255., 255., 255.]
  86. ## Transforms
  87. self.train_img_size = 640
  88. self.test_img_size = 640
  89. self.use_ablu = True
  90. self.affine_params = {
  91. 'degrees': 0.0,
  92. 'translate': 0.2,
  93. 'scale': [0.1, 2.0],
  94. 'shear': 0.0,
  95. 'perspective': 0.0,
  96. 'hsv_h': 0.015,
  97. 'hsv_s': 0.7,
  98. 'hsv_v': 0.4,
  99. }
  100. def print_config(self):
  101. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  102. for k, v in config_dict.items():
  103. print("{} : {}".format(k, v))
  104. # YOLOv5AF-S
  105. class Yolov5AFSConfig(Yolov5AFBaseConfig):
  106. def __init__(self) -> None:
  107. super().__init__()
  108. # ---------------- Model config ----------------
  109. self.width = 0.50
  110. self.depth = 0.34
  111. self.scale = "s"
  112. # ---------------- Data process config ----------------
  113. self.mosaic_prob = 1.0
  114. self.mixup_prob = 0.0
  115. self.copy_paste = 0.5