fcos_config.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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.per_image_lr = 0.01 / 16
  61. self.bk_lr_ratio = 1.0 / 1.0
  62. self.momentum = 0.9
  63. self.weight_decay = 1e-4
  64. self.clip_max_norm = -1.0
  65. # --------- LR Scheduler ---------
  66. self.lr_scheduler = 'step'
  67. self.warmup = 'linear'
  68. self.warmup_iters = 500
  69. self.warmup_factor = 0.00066667
  70. # --------- Train epoch ---------
  71. self.max_epoch = 12, # 1x
  72. self.lr_epoch = [8, 11] # 1x
  73. # --------- Data process ---------
  74. ## input size
  75. self.train_min_size = [800] # short edge of image
  76. self.train_max_size = 1333
  77. self.test_min_size = [800]
  78. self.test_max_size = 1333
  79. ## Pixel mean & std
  80. self.pixel_mean = [0.485, 0.456, 0.406]
  81. self.pixel_std = [0.229, 0.224, 0.225]
  82. ## Transforms
  83. self.box_format = 'xyxy'
  84. self.normalize_coords = False
  85. self.detr_style = False
  86. self.trans_config = [
  87. {'name': 'RandomHFlip'},
  88. {'name': 'RandomResize'},
  89. ]
  90. def print_config(self):
  91. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  92. for k, v in config_dict.items():
  93. print("{} : {}".format(k, v))
  94. class Fcos_R18_1x_Config(FcosBaseConfig):
  95. def __init__(self) -> None:
  96. super().__init__()
  97. ## Backbone
  98. self.backbone = "resnet18"
  99. class Fcos_R50_1x_Config(FcosBaseConfig):
  100. def __init__(self) -> None:
  101. super().__init__()
  102. ## Backbone
  103. self.backbone = "resnet50"
  104. class FcosRT_R18_1x_Config(FcosBaseConfig):
  105. def __init__(self) -> None:
  106. super().__init__()
  107. ## Backbone
  108. self.backbone = "resnet18"
  109. self.max_stride = 32
  110. self.out_stride = [8, 16, 32]
  111. # --------- Neck ---------
  112. self.neck = 'basic_fpn'
  113. self.fpn_p6_feat = False
  114. self.fpn_p7_feat = False
  115. self.fpn_p6_from_c5 = False
  116. # --------- Label Assignment ---------
  117. self.matcher = 'fcos_matcher'
  118. self.matcher_hpy = {'center_sampling_radius': 1.5,
  119. 'object_sizes_of_interest': [[-1, 64],
  120. [64, 128],
  121. [128, float('inf')]]
  122. },
  123. # --------- Train epoch ---------
  124. self.max_epoch = 36, # 3x
  125. self.lr_epoch = [24, 33] # 3x
  126. # --------- Data process ---------
  127. ## input size
  128. self.train_min_size = [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608] # short edge of image
  129. self.train_max_size = 900
  130. self.test_min_size = [512]
  131. self.test_max_size = 736
  132. ## Pixel mean & std
  133. self.pixel_mean = [0.485, 0.456, 0.406]
  134. self.pixel_std = [0.229, 0.224, 0.225]
  135. ## Transforms
  136. self.box_format = 'xyxy'
  137. self.normalize_coords = False
  138. self.detr_style = False
  139. self.trans_config = [
  140. {'name': 'RandomHFlip'},
  141. {'name': 'RandomResize'},
  142. ]
  143. class FcosRT_R50_1x_Config(FcosBaseConfig):
  144. def __init__(self) -> None:
  145. super().__init__()
  146. ## Backbone
  147. self.backbone = "resnet50"
  148. self.max_stride = 32
  149. self.out_stride = [8, 16, 32]
  150. # --------- Neck ---------
  151. self.neck = 'basic_fpn'
  152. self.fpn_p6_feat = False
  153. self.fpn_p7_feat = False
  154. self.fpn_p6_from_c5 = False
  155. # --------- Label Assignment ---------
  156. self.matcher = 'fcos_matcher'
  157. self.matcher_hpy = {'center_sampling_radius': 1.5,
  158. 'object_sizes_of_interest': [[-1, 64],
  159. [64, 128],
  160. [128, float('inf')]]
  161. },
  162. # --------- Train epoch ---------
  163. self.max_epoch = 36, # 3x
  164. self.lr_epoch = [24, 33] # 3x
  165. # --------- Data process ---------
  166. ## input size
  167. self.train_min_size = [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608] # short edge of image
  168. self.train_max_size = 900
  169. self.test_min_size = [512]
  170. self.test_max_size = 736
  171. ## Pixel mean & std
  172. self.pixel_mean = [0.485, 0.456, 0.406]
  173. self.pixel_std = [0.229, 0.224, 0.225]
  174. ## Transforms
  175. self.box_format = 'xyxy'
  176. self.normalize_coords = False
  177. self.detr_style = False
  178. self.trans_config = [
  179. {'name': 'RandomHFlip'},
  180. {'name': 'RandomResize'},
  181. ]