fcos_config.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. else:
  6. raise NotImplementedError("No config for model: {}".format(args.model))
  7. class FcosBaseConfig(object):
  8. def __init__(self):
  9. pass
  10. def print_config(self):
  11. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  12. for k, v in config_dict.items():
  13. print("{} : {}".format(k, v))
  14. class Fcos_R18_1x_Config(FcosBaseConfig):
  15. def __init__(self) -> None:
  16. super().__init__()
  17. ## Backbone
  18. pass
  19. fcos_cfg = {
  20. 'fcos_r18_1x':{
  21. # ----------------- Model-----------------
  22. ## Backbone
  23. 'backbone': 'resnet18',
  24. 'backbone_norm': 'FrozeBN',
  25. 'res5_dilation': False,
  26. 'pretrained': True,
  27. 'freeze_at': 1, # freeze stem layer + layer1 of the backbone
  28. 'pretrained_weight': 'imagenet1k_v1',
  29. 'max_stride': 128,
  30. 'out_stride': [8, 16, 32, 64, 128],
  31. ## Neck
  32. 'neck': 'basic_fpn',
  33. 'fpn_p6_feat': True,
  34. 'fpn_p7_feat': True,
  35. 'fpn_p6_from_c5': False,
  36. ## Head
  37. 'head': 'fcos_head',
  38. 'head_dim': 256,
  39. 'num_cls_head': 4,
  40. 'num_reg_head': 4,
  41. 'head_act': 'relu',
  42. 'head_norm': 'GN',
  43. ## Post-process
  44. 'train_topk': 1000,
  45. 'train_conf_thresh': 0.05,
  46. 'train_nms_thresh': 0.6,
  47. 'test_topk': 100,
  48. 'test_conf_thresh': 0.5,
  49. 'test_nms_thresh': 0.45,
  50. 'nms_class_agnostic': True, # We prefer to use class-agnostic NMS in the demo.
  51. # ----------------- Label Assignment -----------------
  52. 'matcher': 'fcos_matcher',
  53. 'matcher_hpy':{'center_sampling_radius': 1.5,
  54. 'object_sizes_of_interest': [[-1, 64], [64, 128], [128, 256], [256, 512], [512, float('inf')]]
  55. },
  56. # ----------------- Loss weight -----------------
  57. ## Loss hyper-parameters
  58. 'focal_loss_alpha': 0.25,
  59. 'focal_loss_gamma': 2.0,
  60. 'loss_cls_weight': 1.0,
  61. 'loss_reg_weight': 1.0,
  62. 'loss_ctn_weight': 1.0,
  63. # ----------------- Training -----------------
  64. ## Training scheduler
  65. 'scheduler': '1x',
  66. ## Optimizer
  67. 'optimizer': 'sgd',
  68. 'base_lr': 0.01 / 16,
  69. 'backbone_lr_ratio': 1.0 / 1.0,
  70. 'momentum': 0.9,
  71. 'weight_decay': 1e-4,
  72. 'clip_max_norm': -1.0,
  73. 'param_dict_type': 'default',
  74. ## LR Scheduler
  75. 'lr_scheduler': 'step',
  76. 'warmup': 'linear',
  77. 'warmup_iters': 500,
  78. 'warmup_factor': 0.00066667,
  79. ## Epoch
  80. 'max_epoch': 12, # 1x
  81. 'lr_epoch': [8, 11], # 1x
  82. # ----------------- Input -----------------
  83. ## Transforms
  84. 'train_min_size': [800], # short edge of image
  85. 'train_max_size': 1333,
  86. 'test_min_size': [800],
  87. 'test_max_size': 1333,
  88. ## Pixel mean & std
  89. 'pixel_mean': [0.485, 0.456, 0.406],
  90. 'pixel_std': [0.229, 0.224, 0.225],
  91. ## Transforms
  92. 'detr_style': False,
  93. 'trans_config': [
  94. {'name': 'RandomHFlip'},
  95. {'name': 'RandomResize'},
  96. ],
  97. 'box_format': 'xyxy',
  98. 'normalize_coords': False,
  99. },
  100. 'fcos_r50_1x':{
  101. # ----------------- Model-----------------
  102. ## Backbone
  103. 'backbone': 'resnet50',
  104. 'backbone_norm': 'FrozeBN',
  105. 'res5_dilation': False,
  106. 'pretrained': True,
  107. 'freeze_at': 1, # freeze stem layer + layer1 of the backbone
  108. 'pretrained_weight': 'imagenet1k_v1',
  109. 'max_stride': 128,
  110. 'out_stride': [8, 16, 32, 64, 128],
  111. ## Neck
  112. 'neck': 'basic_fpn',
  113. 'fpn_p6_feat': True,
  114. 'fpn_p7_feat': True,
  115. 'fpn_p6_from_c5': False,
  116. ## Head
  117. 'head': 'fcos_head',
  118. 'head_dim': 256,
  119. 'num_cls_head': 4,
  120. 'num_reg_head': 4,
  121. 'head_act': 'relu',
  122. 'head_norm': 'GN',
  123. ## Post-process
  124. 'train_topk': 1000,
  125. 'train_conf_thresh': 0.05,
  126. 'train_nms_thresh': 0.65,
  127. 'test_topk': 100,
  128. 'test_conf_thresh': 0.5,
  129. 'test_nms_thresh': 0.45,
  130. 'nms_class_agnostic': True, # We prefer to use class-agnostic NMS in the demo.
  131. # ----------------- Label Assignment -----------------
  132. 'matcher': 'fcos_matcher',
  133. 'matcher_hpy':{'center_sampling_radius': 1.5,
  134. 'object_sizes_of_interest': [[-1, 64], [64, 128], [128, 256], [256, 512], [512, float('inf')]]
  135. },
  136. # ----------------- Loss weight -----------------
  137. ## Loss hyper-parameters
  138. 'focal_loss_alpha': 0.25,
  139. 'focal_loss_gamma': 2.0,
  140. 'loss_cls_weight': 1.0,
  141. 'loss_reg_weight': 1.0,
  142. 'loss_ctn_weight': 1.0,
  143. # ----------------- Training -----------------
  144. ## Training scheduler
  145. 'scheduler': '1x',
  146. ## Optimizer
  147. 'optimizer': 'sgd',
  148. 'base_lr': 0.01 / 16,
  149. 'backbone_lr_ratio': 1.0 / 1.0,
  150. 'momentum': 0.9,
  151. 'weight_decay': 1e-4,
  152. 'clip_max_norm': -1.0,
  153. 'param_dict_type': 'default',
  154. ## LR Scheduler
  155. 'lr_scheduler': 'step',
  156. 'warmup': 'linear',
  157. 'warmup_iters': 500,
  158. 'warmup_factor': 0.00066667,
  159. ## Epoch
  160. 'max_epoch': 12, # 1x
  161. 'lr_epoch': [8, 11], # 1x
  162. # ----------------- Input -----------------
  163. ## Transforms
  164. 'train_min_size': [800], # short edge of image
  165. 'train_max_size': 1333,
  166. 'test_min_size': [800],
  167. 'test_max_size': 1333,
  168. ## Pixel mean & std
  169. 'pixel_mean': [0.485, 0.456, 0.406],
  170. 'pixel_std': [0.229, 0.224, 0.225],
  171. ## Transforms
  172. 'detr_style': False,
  173. 'trans_config': [
  174. {'name': 'RandomHFlip'},
  175. {'name': 'RandomResize'},
  176. ],
  177. 'box_format': 'xyxy',
  178. 'normalize_coords': False,
  179. },
  180. 'fcos_rt_r18_1x':{
  181. # ----------------- Model-----------------
  182. ## Backbone
  183. 'backbone': 'resnet18',
  184. 'backbone_norm': 'FrozeBN',
  185. 'res5_dilation': False,
  186. 'pretrained': True,
  187. 'freeze_at': 1, # freeze stem layer + layer1 of the backbone
  188. 'pretrained_weight': 'imagenet1k_v1',
  189. 'max_stride': 32,
  190. 'out_stride': [8, 16, 32],
  191. ## Neck
  192. 'neck': 'basic_fpn',
  193. 'fpn_p6_feat': False,
  194. 'fpn_p7_feat': False,
  195. 'fpn_p6_from_c5': False,
  196. ## Head
  197. 'head': 'fcos_head',
  198. 'head_dim': 256,
  199. 'num_cls_head': 4,
  200. 'num_reg_head': 4,
  201. 'head_act': 'relu',
  202. 'head_norm': 'GN',
  203. ## Post-process
  204. 'train_topk': 1000,
  205. 'train_conf_thresh': 0.05,
  206. 'train_nms_thresh': 0.6,
  207. 'test_topk': 100,
  208. 'test_conf_thresh': 0.5,
  209. 'test_nms_thresh': 0.45,
  210. 'nms_class_agnostic': True, # We prefer to use class-agnostic NMS in the demo.
  211. # ----------------- Label Assignment -----------------
  212. 'matcher': 'fcos_matcher',
  213. 'matcher_hpy':{'center_sampling_radius': 1.5,
  214. 'object_sizes_of_interest': [[-1, 64], [64, 128], [128, float('inf')]]
  215. },
  216. # ----------------- Loss weight -----------------
  217. ## Loss hyper-parameters
  218. 'focal_loss_alpha': 0.25,
  219. 'focal_loss_gamma': 2.0,
  220. 'loss_cls_weight': 1.0,
  221. 'loss_reg_weight': 1.0,
  222. 'loss_ctn_weight': 1.0,
  223. # ----------------- Training -----------------
  224. ## Training scheduler
  225. 'scheduler': '1x',
  226. ## Optimizer
  227. 'optimizer': 'sgd',
  228. 'base_lr': 0.01 / 16,
  229. 'backbone_lr_ratio': 1.0 / 1.0,
  230. 'momentum': 0.9,
  231. 'weight_decay': 1e-4,
  232. 'clip_max_norm': -1.0,
  233. ## LR Scheduler
  234. 'lr_scheduler': 'step',
  235. 'warmup': 'linear',
  236. 'warmup_iters': 500,
  237. 'warmup_factor': 0.00066667,
  238. ## Epoch
  239. 'max_epoch': 36, # 1x
  240. 'lr_epoch': [24, 33], # 1x
  241. # ----------------- Input -----------------
  242. ## Transforms
  243. 'train_min_size': [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608], # short edge of image
  244. 'train_max_size': 900,
  245. 'test_min_size': [512],
  246. 'test_max_size': 736,
  247. ## Pixel mean & std
  248. 'pixel_mean': [0.485, 0.456, 0.406],
  249. 'pixel_std': [0.229, 0.224, 0.225],
  250. ## Transforms
  251. 'detr_style': False,
  252. 'trans_config': [
  253. {'name': 'RandomHFlip'},
  254. {'name': 'RandomResize'},
  255. ],
  256. 'box_format': 'xyxy',
  257. 'normalize_coords': False,
  258. },
  259. 'fcos_rt_r50_1x':{
  260. # ----------------- Model-----------------
  261. ## Backbone
  262. 'backbone': 'resnet50',
  263. 'backbone_norm': 'FrozeBN',
  264. 'res5_dilation': False,
  265. 'pretrained': True,
  266. 'freeze_at': 1, # freeze stem layer + layer1 of the backbone
  267. 'pretrained_weight': 'imagenet1k_v1',
  268. 'max_stride': 32,
  269. 'out_stride': [8, 16, 32],
  270. ## Neck
  271. 'neck': 'basic_fpn',
  272. 'fpn_p6_feat': False,
  273. 'fpn_p7_feat': False,
  274. 'fpn_p6_from_c5': False,
  275. ## Head
  276. 'head': 'fcos_head',
  277. 'head_dim': 256,
  278. 'num_cls_head': 4,
  279. 'num_reg_head': 4,
  280. 'head_act': 'relu',
  281. 'head_norm': 'GN',
  282. ## Post-process
  283. 'train_topk': 1000,
  284. 'train_conf_thresh': 0.05,
  285. 'train_nms_thresh': 0.6,
  286. 'test_topk': 100,
  287. 'test_conf_thresh': 0.5,
  288. 'test_nms_thresh': 0.45,
  289. 'nms_class_agnostic': True, # We prefer to use class-agnostic NMS in the demo.
  290. # ----------------- Label Assignment -----------------
  291. 'matcher': 'fcos_matcher',
  292. 'matcher_hpy':{'center_sampling_radius': 1.5,
  293. 'object_sizes_of_interest': [[-1, 64], [64, 128], [128, float('inf')]]
  294. },
  295. # ----------------- Loss weight -----------------
  296. ## Loss hyper-parameters
  297. 'focal_loss_alpha': 0.25,
  298. 'focal_loss_gamma': 2.0,
  299. 'loss_cls_weight': 1.0,
  300. 'loss_reg_weight': 1.0,
  301. 'loss_ctn_weight': 1.0,
  302. # ----------------- Training -----------------
  303. ## Training scheduler
  304. 'scheduler': '1x',
  305. ## Optimizer
  306. 'optimizer': 'sgd',
  307. 'base_lr': 0.01 / 16,
  308. 'backbone_lr_ratio': 1.0 / 1.0,
  309. 'momentum': 0.9,
  310. 'weight_decay': 1e-4,
  311. 'clip_max_norm': -1.0,
  312. ## LR Scheduler
  313. 'lr_scheduler': 'step',
  314. 'warmup': 'linear',
  315. 'warmup_iters': 500,
  316. 'warmup_factor': 0.00066667,
  317. ## Epoch
  318. 'max_epoch': 36, # 1x
  319. 'lr_epoch': [24, 33], # 1x
  320. # ----------------- Input -----------------
  321. ## Transforms
  322. 'train_min_size': [256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608], # short edge of image
  323. 'train_max_size': 900,
  324. 'test_min_size': [512],
  325. 'test_max_size': 736,
  326. ## Pixel mean & std
  327. 'pixel_mean': [0.485, 0.456, 0.406],
  328. 'pixel_std': [0.229, 0.224, 0.225],
  329. ## Transforms
  330. 'detr_style': False,
  331. 'trans_config': [
  332. {'name': 'RandomHFlip'},
  333. {'name': 'RandomResize'},
  334. ],
  335. 'box_format': 'xyxy',
  336. 'normalize_coords': False,
  337. },
  338. }