yolof_config.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Yolof Config
  2. def build_yolof_config(args):
  3. if args.model == 'yolof_r18':
  4. return YolofR18Config()
  5. elif args.model == 'yolof_r50':
  6. return YolofR50Config()
  7. else:
  8. raise NotImplementedError("No config for model: {}".format(args.model))
  9. # Fcos-Base config
  10. class YolofBaseConfig(object):
  11. def __init__(self) -> None:
  12. # ---------------- Model config ----------------
  13. self.out_stride = 32
  14. self.max_stride = 32
  15. ## Backbone
  16. self.backbone = 'resnet50'
  17. self.use_pretrained = True
  18. ## Encoder
  19. self.neck_expand_ratio = 0.25
  20. self.neck_dilations = [2, 4, 6, 8]
  21. ## Head
  22. self.head_dim = 512
  23. self.num_cls_head = 2
  24. self.num_reg_head = 4
  25. # ---------------- Post-process config ----------------
  26. ## Post process
  27. self.val_topk = 1000
  28. self.val_conf_thresh = 0.05
  29. self.val_nms_thresh = 0.6
  30. self.test_topk = 300
  31. self.test_conf_thresh = 0.3
  32. self.test_nms_thresh = 0.45
  33. # ---------------- Assignment config ----------------
  34. ## Matcher
  35. self.center_clamp = 32
  36. self.match_topk_candidates = 4
  37. self.match_iou_thresh = 0.15
  38. self.ignore_thresh = 0.7
  39. self.anchor_size = [[32, 32], [64, 64], [128, 128], [256, 256], [512, 512]]
  40. ## Loss weight
  41. self.focal_loss_alpha = 0.25
  42. self.focal_loss_gamma = 2.0
  43. self.loss_cls = 1.0
  44. self.loss_reg = 1.0
  45. self.loss_ctn = 1.0
  46. # ---------------- ModelEMA config ----------------
  47. self.use_ema = True
  48. self.ema_decay = 0.9998
  49. self.ema_tau = 2000
  50. # ---------------- Optimizer config ----------------
  51. self.trainer = 'yolo'
  52. self.optimizer = 'adamw'
  53. self.base_lr = 0.001 # base_lr = per_image_lr * batch_size
  54. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  55. self.batch_size_base = 64
  56. self.momentum = 0.9
  57. self.weight_decay = 0.05
  58. self.clip_max_norm = 35.0
  59. self.warmup_bias_lr = 0.1
  60. self.warmup_momentum = 0.8
  61. # ---------------- Lr Scheduler config ----------------
  62. self.warmup_epoch = 3
  63. self.lr_scheduler = "cosine"
  64. self.max_epoch = 150
  65. self.eval_epoch = 10
  66. self.no_aug_epoch = -1
  67. # ---------------- Data process config ----------------
  68. self.aug_type = 'yolo'
  69. self.mosaic_prob = 0.0
  70. self.mixup_prob = 0.0
  71. self.copy_paste = 0.0 # approximated by the YOLOX's mixup
  72. self.multi_scale = [0.5, 1.5] # multi scale: [img_size * 0.5, img_size * 1.5]
  73. ## Pixel mean & std
  74. self.pixel_mean = [0., 0., 0.]
  75. self.pixel_std = [255., 255., 255.]
  76. ## Transforms
  77. self.train_img_size = 640
  78. self.test_img_size = 640
  79. self.affine_params = {
  80. 'degrees': 0.0,
  81. 'translate': 0.1,
  82. 'scale': [0.5, 1.5],
  83. 'shear': 0.0,
  84. 'perspective': 0.0,
  85. 'hsv_h': 0.015,
  86. 'hsv_s': 0.7,
  87. 'hsv_v': 0.4,
  88. }
  89. def print_config(self):
  90. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  91. for k, v in config_dict.items():
  92. print("{} : {}".format(k, v))
  93. # YOLOv2-R18
  94. class YolofR18Config(YolofBaseConfig):
  95. def __init__(self) -> None:
  96. super().__init__()
  97. self.backbone = 'resnet18'
  98. # YOLOv2-R50
  99. class YolofR50Config(YolofBaseConfig):
  100. def __init__(self) -> None:
  101. super().__init__()
  102. # TODO: Try your best.