fcos_config.py 3.4 KB

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