fcos_config.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. # --------- Data process ---------
  75. ## input size
  76. self.train_min_size = [800] # short edge of image
  77. self.train_max_size = 1333
  78. self.test_min_size = [800]
  79. self.test_max_size = 1333
  80. ## Pixel mean & std
  81. self.pixel_mean = [0.485, 0.456, 0.406]
  82. self.pixel_std = [0.229, 0.224, 0.225]
  83. ## Transforms
  84. self.box_format = 'xyxy'
  85. self.normalize_coords = False
  86. self.detr_style = False
  87. self.trans_config = [
  88. {'name': 'RandomHFlip'},
  89. {'name': 'RandomResize'},
  90. ]
  91. def print_config(self):
  92. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  93. for k, v in config_dict.items():
  94. print("{} : {}".format(k, v))
  95. class Fcos_R18_1x_Config(FcosBaseConfig):
  96. def __init__(self) -> None:
  97. super().__init__()
  98. ## Backbone
  99. self.backbone = "resnet18"
  100. class Fcos_R50_1x_Config(FcosBaseConfig):
  101. def __init__(self) -> None:
  102. super().__init__()
  103. ## Backbone
  104. self.backbone = "resnet50"
  105. class FcosRT_R18_1x_Config(FcosBaseConfig):
  106. def __init__(self) -> None:
  107. super().__init__()
  108. ## Backbone
  109. self.backbone = "resnet18"
  110. self.max_stride = 32
  111. self.out_stride = [8, 16, 32]
  112. # --------- Neck ---------
  113. self.neck = 'basic_fpn'
  114. self.fpn_p6_feat = False
  115. self.fpn_p7_feat = False
  116. self.fpn_p6_from_c5 = False
  117. # --------- Label Assignment ---------
  118. self.matcher = 'simota'
  119. self.matcher_hpy = {'soft_center_radius': 2.5,
  120. 'topk_candidates': 13},
  121. # --------- Loss weight ---------
  122. self.focal_loss_alpha = 0.25
  123. self.focal_loss_gamma = 2.0
  124. self.loss_cls_weight = 1.0
  125. self.loss_reg_weight = 2.0
  126. self.loss_ctn_weight = 0.5
  127. # --------- Train epoch ---------
  128. self.max_epoch = 36, # 3x
  129. self.lr_epoch = [24, 33] # 3x
  130. # --------- Data process ---------
  131. ## input size
  132. self.train_min_size = [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608] # short edge of image
  133. self.train_max_size = 900
  134. self.test_min_size = [512]
  135. self.test_max_size = 736
  136. ## Pixel mean & std
  137. self.pixel_mean = [0.485, 0.456, 0.406]
  138. self.pixel_std = [0.229, 0.224, 0.225]
  139. ## Transforms
  140. self.box_format = 'xyxy'
  141. self.normalize_coords = False
  142. self.detr_style = False
  143. self.trans_config = [
  144. {'name': 'RandomHFlip'},
  145. {'name': 'RandomResize'},
  146. ]
  147. class FcosRT_R50_1x_Config(FcosBaseConfig):
  148. def __init__(self) -> None:
  149. super().__init__()
  150. ## Backbone
  151. self.backbone = "resnet50"
  152. self.max_stride = 32
  153. self.out_stride = [8, 16, 32]
  154. # --------- Neck ---------
  155. self.neck = 'basic_fpn'
  156. self.fpn_p6_feat = False
  157. self.fpn_p7_feat = False
  158. self.fpn_p6_from_c5 = False
  159. # --------- Label Assignment ---------
  160. self.matcher = 'simota'
  161. self.matcher_hpy = {'soft_center_radius': 2.5,
  162. 'topk_candidates': 13},
  163. # --------- Loss weight ---------
  164. self.focal_loss_alpha = 0.25
  165. self.focal_loss_gamma = 2.0
  166. self.loss_cls_weight = 1.0
  167. self.loss_reg_weight = 2.0
  168. self.loss_ctn_weight = 0.5
  169. # --------- Train epoch ---------
  170. self.max_epoch = 36, # 3x
  171. self.lr_epoch = [24, 33] # 3x
  172. # --------- Data process ---------
  173. ## input size
  174. self.train_min_size = [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608] # short edge of image
  175. self.train_max_size = 900
  176. self.test_min_size = [512]
  177. self.test_max_size = 736
  178. ## Pixel mean & std
  179. self.pixel_mean = [0.485, 0.456, 0.406]
  180. self.pixel_std = [0.229, 0.224, 0.225]
  181. ## Transforms
  182. self.box_format = 'xyxy'
  183. self.normalize_coords = False
  184. self.detr_style = False
  185. self.trans_config = [
  186. {'name': 'RandomHFlip'},
  187. {'name': 'RandomResize'},
  188. ]