fcos_config.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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_1x':
  8. return FcosRT_R18_1x_Config()
  9. elif args.model == 'fcos_rt_r50_1x':
  10. return FcosRT_R50_1x_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_1x_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. # --------- Label Assignment ---------
  119. self.matcher = 'simota'
  120. self.matcher_hpy = {'soft_center_radius': 2.5,
  121. 'topk_candidates': 13},
  122. # --------- Loss weight ---------
  123. self.focal_loss_alpha = 0.25
  124. self.focal_loss_gamma = 2.0
  125. self.loss_cls_weight = 1.0
  126. self.loss_reg_weight = 2.0
  127. self.loss_ctn_weight = 0.5
  128. # --------- Train epoch ---------
  129. self.max_epoch = 36, # 3x
  130. self.lr_epoch = [24, 33] # 3x
  131. # --------- Data process ---------
  132. ## input size
  133. self.train_min_size = [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608] # short edge of image
  134. self.train_max_size = 900
  135. self.test_min_size = [512]
  136. self.test_max_size = 736
  137. ## Pixel mean & std
  138. self.pixel_mean = [0.485, 0.456, 0.406]
  139. self.pixel_std = [0.229, 0.224, 0.225]
  140. ## Transforms
  141. self.box_format = 'xyxy'
  142. self.normalize_coords = False
  143. self.detr_style = False
  144. self.trans_config = [
  145. {'name': 'RandomHFlip'},
  146. {'name': 'RandomResize'},
  147. ]
  148. class FcosRT_R50_1x_Config(FcosBaseConfig):
  149. def __init__(self) -> None:
  150. super().__init__()
  151. ## Backbone
  152. self.backbone = "resnet50"
  153. self.max_stride = 32
  154. self.out_stride = [8, 16, 32]
  155. # --------- Neck ---------
  156. self.neck = 'basic_fpn'
  157. self.fpn_p6_feat = False
  158. self.fpn_p7_feat = False
  159. self.fpn_p6_from_c5 = False
  160. # --------- Label Assignment ---------
  161. self.matcher = 'simota'
  162. self.matcher_hpy = {'soft_center_radius': 2.5,
  163. 'topk_candidates': 13},
  164. # --------- Loss weight ---------
  165. self.focal_loss_alpha = 0.25
  166. self.focal_loss_gamma = 2.0
  167. self.loss_cls_weight = 1.0
  168. self.loss_reg_weight = 2.0
  169. self.loss_ctn_weight = 0.5
  170. # --------- Train epoch ---------
  171. self.max_epoch = 36, # 3x
  172. self.lr_epoch = [24, 33] # 3x
  173. # --------- Data process ---------
  174. ## input size
  175. self.train_min_size = [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608] # short edge of image
  176. self.train_max_size = 900
  177. self.test_min_size = [512]
  178. self.test_max_size = 736
  179. ## Pixel mean & std
  180. self.pixel_mean = [0.485, 0.456, 0.406]
  181. self.pixel_std = [0.229, 0.224, 0.225]
  182. ## Transforms
  183. self.box_format = 'xyxy'
  184. self.normalize_coords = False
  185. self.detr_style = False
  186. self.trans_config = [
  187. {'name': 'RandomHFlip'},
  188. {'name': 'RandomResize'},
  189. ]