fcos_config.py 7.4 KB

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