fcos_config.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. elif args.model == 'fcos_e2e_r18_3x':
  16. return FcosE2E_R18_3x_Config()
  17. else:
  18. raise NotImplementedError("No config for model: {}".format(args.model))
  19. # --------------- Base configuration ---------------
  20. class FcosBaseConfig(object):
  21. def __init__(self):
  22. # --------- Backbone ---------
  23. self.backbone = "resnet50"
  24. self.bk_norm = "FrozeBN"
  25. self.res5_dilation = False
  26. self.use_pretrained = True
  27. self.freeze_at = 1
  28. self.max_stride = 128
  29. self.out_stride = [8, 16, 32, 64, 128]
  30. # --------- Neck ---------
  31. self.neck = 'basic_fpn'
  32. self.fpn_p6_feat = True
  33. self.fpn_p7_feat = True
  34. self.fpn_p6_from_c5 = False
  35. # --------- Head ---------
  36. self.head = 'fcos_head'
  37. self.head_dim = 256
  38. self.num_cls_head = 4
  39. self.num_reg_head = 4
  40. self.head_act = 'relu'
  41. self.head_norm = 'GN'
  42. # --------- Post-process ---------
  43. self.train_topk = 1000
  44. self.train_conf_thresh = 0.05
  45. self.train_nms_thresh = 0.6
  46. self.test_topk = 100
  47. self.test_conf_thresh = 0.5
  48. self.test_nms_thresh = 0.45
  49. self.nms_class_agnostic = True
  50. # --------- Label Assignment ---------
  51. self.matcher = 'fcos_matcher'
  52. self.matcher_hpy = {'center_sampling_radius': 1.5,
  53. 'object_sizes_of_interest': [[-1, 64],
  54. [64, 128],
  55. [128, 256],
  56. [256, 512],
  57. [512, float('inf')]]
  58. }
  59. # --------- Loss weight ---------
  60. self.focal_loss_alpha = 0.25
  61. self.focal_loss_gamma = 2.0
  62. self.loss_cls_weight = 1.0
  63. self.loss_reg_weight = 1.0
  64. self.loss_ctn_weight = 1.0
  65. # --------- Optimizer ---------
  66. self.optimizer = 'sgd'
  67. self.batch_size_base = 16
  68. self.per_image_lr = 0.01 / 16
  69. self.bk_lr_ratio = 1.0 / 1.0
  70. self.momentum = 0.9
  71. self.weight_decay = 1e-4
  72. self.clip_max_norm = -1.0
  73. # --------- LR Scheduler ---------
  74. self.lr_scheduler = 'step'
  75. self.warmup = 'linear'
  76. self.warmup_iters = 500
  77. self.warmup_factor = 0.00066667
  78. # --------- Train epoch ---------
  79. self.max_epoch = 12 # 1x
  80. self.lr_epoch = [8, 11] # 1x
  81. self.eval_epoch = 2
  82. # --------- Data process ---------
  83. ## input size
  84. self.train_min_size = [800] # short edge of image
  85. self.train_max_size = 1333
  86. self.test_min_size = [800]
  87. self.test_max_size = 1333
  88. ## Pixel mean & std
  89. self.pixel_mean = [0.485, 0.456, 0.406]
  90. self.pixel_std = [0.229, 0.224, 0.225]
  91. ## Transforms
  92. self.box_format = 'xyxy'
  93. self.normalize_coords = False
  94. self.detr_style = False
  95. self.trans_config = [
  96. {'name': 'RandomHFlip'},
  97. {'name': 'RandomResize'},
  98. ]
  99. def print_config(self):
  100. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  101. for k, v in config_dict.items():
  102. print("{} : {}".format(k, v))
  103. # --------------- 1x scheduler ---------------
  104. class Fcos_R18_1x_Config(FcosBaseConfig):
  105. def __init__(self) -> None:
  106. super().__init__()
  107. ## Backbone
  108. self.backbone = "resnet18"
  109. class Fcos_R50_1x_Config(Fcos_R18_1x_Config):
  110. def __init__(self) -> None:
  111. super().__init__()
  112. self.backbone = "resnet50"
  113. # --------------- 3x scheduler ---------------
  114. class Fcos_R18_3x_Config(Fcos_R18_1x_Config):
  115. def __init__(self) -> None:
  116. super().__init__()
  117. # --------- Train epoch ---------
  118. self.max_epoch = 36 # 3x
  119. self.lr_epoch = [24, 33] # 3x
  120. self.eval_epoch = 2
  121. # --------- Data process ---------
  122. ## input size
  123. self.train_min_size = [480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800] # short edge of image
  124. self.train_max_size = 1333
  125. self.test_min_size = [800]
  126. self.test_max_size = 1333
  127. class Fcos_R50_3x_Config(Fcos_R18_3x_Config):
  128. def __init__(self) -> None:
  129. super().__init__()
  130. ## Backbone
  131. self.backbone = "resnet50"
  132. # --------------- RT-FCOS & 3x scheduler ---------------
  133. class FcosRT_R18_3x_Config(FcosBaseConfig):
  134. def __init__(self) -> None:
  135. super().__init__()
  136. ## Backbone
  137. self.backbone = "resnet18"
  138. self.max_stride = 32
  139. self.out_stride = [8, 16, 32]
  140. # --------- Neck ---------
  141. self.neck = 'basic_fpn'
  142. self.fpn_p6_feat = False
  143. self.fpn_p7_feat = False
  144. self.fpn_p6_from_c5 = False
  145. # --------- Head ---------
  146. self.head = 'fcos_rt_head'
  147. self.head_dim = 256
  148. self.num_cls_head = 4
  149. self.num_reg_head = 4
  150. self.head_act = 'relu'
  151. self.head_norm = 'GN'
  152. # --------- Post-process ---------
  153. self.train_topk = 1000
  154. self.train_conf_thresh = 0.05
  155. self.train_nms_thresh = 0.6
  156. self.test_topk = 100
  157. self.test_conf_thresh = 0.4
  158. self.test_nms_thresh = 0.45
  159. self.nms_class_agnostic = True
  160. # --------- Label Assignment ---------
  161. self.matcher = 'simota'
  162. self.matcher_hpy = {'soft_center_radius': 3.0,
  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. # --------- 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. ]
  189. class FcosRT_R50_3x_Config(FcosRT_R18_3x_Config):
  190. def __init__(self) -> None:
  191. super().__init__()
  192. # --------- Backbone ---------
  193. self.backbone = "resnet50"
  194. # --------------- E2E-FCOS & 3x scheduler ---------------
  195. class FcosE2E_R18_3x_Config(FcosBaseConfig):
  196. def __init__(self) -> None:
  197. super().__init__()
  198. ## Backbone
  199. self.backbone = "resnet18"
  200. self.max_stride = 32
  201. self.out_stride = [8, 16, 32]
  202. # --------- Neck ---------
  203. self.neck = 'basic_fpn'
  204. self.fpn_p6_feat = False
  205. self.fpn_p7_feat = False
  206. self.fpn_p6_from_c5 = False
  207. # --------- Head ---------
  208. self.head = 'fcos_rt_head'
  209. self.head_dim = 256
  210. self.num_cls_head = 4
  211. self.num_reg_head = 4
  212. self.head_act = 'relu'
  213. self.head_norm = 'GN'
  214. # --------- Post-process ---------
  215. self.train_topk = 100
  216. self.train_conf_thresh = 0.05
  217. self.test_topk = 100
  218. self.test_conf_thresh = 0.4
  219. # --------- Label Assignment ---------
  220. self.matcher = 'simota'
  221. self.matcher_hpy = {'soft_center_radius': 3.0,
  222. 'topk_candidates': 13}
  223. # --------- Loss weight ---------
  224. self.focal_loss_alpha = 0.25
  225. self.focal_loss_gamma = 2.0
  226. self.loss_cls_weight = 1.0
  227. self.loss_reg_weight = 2.0
  228. # --------- Train epoch ---------
  229. self.max_epoch = 36 # 3x
  230. self.lr_epoch = [24, 33] # 3x
  231. # --------- Data process ---------
  232. ## input size
  233. self.train_min_size = [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608] # short edge of image
  234. self.train_max_size = 900
  235. self.test_min_size = [512]
  236. self.test_max_size = 736
  237. ## Pixel mean & std
  238. self.pixel_mean = [0.485, 0.456, 0.406]
  239. self.pixel_std = [0.229, 0.224, 0.225]
  240. ## Transforms
  241. self.box_format = 'xyxy'
  242. self.normalize_coords = False
  243. self.detr_style = False
  244. self.trans_config = [
  245. {'name': 'RandomHFlip'},
  246. {'name': 'RandomResize'},
  247. ]