fcos_config.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Fully Convolutional One-Stage object detector
  2. def build_fcos_config(args):
  3. # Standard FCOS 1x
  4. if args.model == 'fcos_r18_1x':
  5. return Fcos_R18_1x_Config()
  6. elif args.model == 'fcos_r50_1x':
  7. return Fcos_R50_1x_Config()
  8. # Standard FCOS 3x
  9. elif args.model == 'fcos_r18_3x':
  10. return Fcos_R18_3x_Config()
  11. elif args.model == 'fcos_r50_3x':
  12. return Fcos_R50_3x_Config()
  13. else:
  14. raise NotImplementedError("No config for model: {}".format(args.model))
  15. # --------------- Base configuration ---------------
  16. class FcosBaseConfig(object):
  17. def __init__(self):
  18. # --------- Backbone ---------
  19. self.backbone = "resnet50"
  20. self.bk_norm = "FrozeBN"
  21. self.res5_dilation = False
  22. self.use_pretrained = True
  23. self.freeze_at = 1
  24. self.max_stride = 128
  25. self.out_stride = [8, 16, 32, 64, 128]
  26. # --------- Neck ---------
  27. self.neck = 'basic_fpn'
  28. self.fpn_p6_feat = True
  29. self.fpn_p7_feat = True
  30. self.fpn_p6_from_c5 = False
  31. # --------- Head ---------
  32. self.head = 'fcos_head'
  33. self.head_dim = 256
  34. self.num_cls_head = 4
  35. self.num_reg_head = 4
  36. self.head_act = 'relu'
  37. self.head_norm = 'GN'
  38. # --------- Post-process ---------
  39. self.train_topk = 1000
  40. self.train_conf_thresh = 0.05
  41. self.train_nms_thresh = 0.6
  42. self.test_topk = 100
  43. self.test_conf_thresh = 0.5
  44. self.test_nms_thresh = 0.45
  45. self.nms_class_agnostic = True
  46. # --------- Label Assignment ---------
  47. self.matcher = 'fcos_matcher'
  48. self.matcher_hpy = {'center_sampling_radius': 1.5,
  49. 'object_sizes_of_interest': [[-1, 64],
  50. [64, 128],
  51. [128, 256],
  52. [256, 512],
  53. [512, float('inf')]]
  54. }
  55. # --------- Loss weight ---------
  56. self.focal_loss_alpha = 0.25
  57. self.focal_loss_gamma = 2.0
  58. self.loss_cls_weight = 1.0
  59. self.loss_reg_weight = 1.0
  60. self.loss_ctn_weight = 1.0
  61. # --------- Optimizer ---------
  62. self.optimizer = 'sgd'
  63. self.batch_size_base = 16
  64. self.per_image_lr = 0.01 / 16
  65. self.bk_lr_ratio = 1.0 / 1.0
  66. self.momentum = 0.9
  67. self.weight_decay = 1e-4
  68. self.clip_max_norm = -1.0
  69. # --------- LR Scheduler ---------
  70. self.lr_scheduler = 'step'
  71. self.warmup = 'linear'
  72. self.warmup_iters = 500
  73. self.warmup_factor = 0.00066667
  74. # --------- Train epoch ---------
  75. self.max_epoch = 12 # 1x
  76. self.lr_epoch = [8, 11] # 1x
  77. self.eval_epoch = 2
  78. # --------- Data process ---------
  79. ## input size
  80. self.train_min_size = [800] # short edge of image
  81. self.train_max_size = 1333
  82. self.test_min_size = [800]
  83. self.test_max_size = 1333
  84. ## Pixel mean & std
  85. self.pixel_mean = [0.485, 0.456, 0.406]
  86. self.pixel_std = [0.229, 0.224, 0.225]
  87. ## Transforms
  88. self.box_format = 'xyxy'
  89. self.normalize_coords = False
  90. self.detr_style = False
  91. self.trans_config = [
  92. {'name': 'RandomHFlip'},
  93. {'name': 'RandomResize'},
  94. ]
  95. def print_config(self):
  96. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  97. for k, v in config_dict.items():
  98. print("{} : {}".format(k, v))
  99. # --------------- 1x scheduler ---------------
  100. class Fcos_R18_1x_Config(FcosBaseConfig):
  101. def __init__(self) -> None:
  102. super().__init__()
  103. ## Backbone
  104. self.backbone = "resnet18"
  105. class Fcos_R50_1x_Config(Fcos_R18_1x_Config):
  106. def __init__(self) -> None:
  107. super().__init__()
  108. self.backbone = "resnet50"
  109. # --------------- 3x scheduler ---------------
  110. class Fcos_R18_3x_Config(Fcos_R18_1x_Config):
  111. def __init__(self) -> None:
  112. super().__init__()
  113. # --------- Train epoch ---------
  114. self.max_epoch = 36 # 3x
  115. self.lr_epoch = [24, 33] # 3x
  116. self.eval_epoch = 2
  117. # --------- Data process ---------
  118. ## input size
  119. self.train_min_size = [480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800] # short edge of image
  120. self.train_max_size = 1333
  121. self.test_min_size = [800]
  122. self.test_max_size = 1333
  123. class Fcos_R50_3x_Config(Fcos_R18_3x_Config):
  124. def __init__(self) -> None:
  125. super().__init__()
  126. ## Backbone
  127. self.backbone = "resnet50"