fcos_config.py 7.1 KB

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