fcos_config.py 6.0 KB

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