yolof_config.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. # Fully Convolutional One-Stage object detector
  2. def build_yolof_config(args):
  3. if args.model == 'yolof_r18_c5_1x':
  4. return Yolof_R18_C5_1x_Config()
  5. else:
  6. raise NotImplementedError("No config for model: {}".format(args.model))
  7. class YolofBaseConfig(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 Yolof_R18_C5_1x_Config(YolofBaseConfig):
  15. def __init__(self) -> None:
  16. super().__init__()
  17. ## Backbone
  18. pass
  19. yolof_cfg = {
  20. # --------------- C5 level ---------------
  21. 'yolof_r18_c5_1x':{
  22. # ----------------- Model-----------------
  23. ## Backbone
  24. 'backbone': 'resnet18',
  25. 'backbone_norm': 'FrozeBN',
  26. 'res5_dilation': False,
  27. 'pretrained': True,
  28. 'pretrained_weight': 'imagenet1k_v1',
  29. 'freeze_at': 1, # freeze stem layer + layer1 of the backbone
  30. 'max_stride': 32,
  31. 'out_stride': 32,
  32. ## Neck
  33. 'neck': 'dilated_encoder',
  34. 'neck_dilations': [2, 4, 6, 8],
  35. 'neck_expand_ratio': 0.25,
  36. 'neck_act': 'relu',
  37. 'neck_norm': 'BN',
  38. ## Head
  39. 'head': 'yolof_head',
  40. 'head_dim': 512,
  41. 'num_cls_head': 2,
  42. 'num_reg_head': 4,
  43. 'head_act': 'relu',
  44. 'head_norm': 'BN',
  45. 'center_clamp': 32,
  46. 'anchor_size': [[32, 32], [64, 64], [128, 128], [256, 256], [512, 512]],
  47. ## Post-process
  48. 'train_topk': 1000,
  49. 'train_conf_thresh': 0.05,
  50. 'train_nms_thresh': 0.6,
  51. 'test_topk': 300,
  52. 'test_conf_thresh': 0.3,
  53. 'test_nms_thresh': 0.45,
  54. 'nms_class_agnostic': True, # We prefer to use class-agnostic NMS in the demo.
  55. # ----------------- Label Assignment -----------------
  56. 'matcher': 'yolof_matcher',
  57. 'matcher_hpy': {'topk_candidates': 4,
  58. 'iou_thresh': 0.15,
  59. 'ignore_thresh': 0.7,
  60. },
  61. # ----------------- Loss weight -----------------
  62. ## Loss hyper-parameters
  63. 'focal_loss_alpha': 0.25,
  64. 'focal_loss_gamma': 2.0,
  65. 'loss_cls_weight': 1.0,
  66. 'loss_reg_weight': 1.0,
  67. # ----------------- Training -----------------
  68. ## Training scheduler
  69. 'scheduler': '1x',
  70. ## Optimizer
  71. 'optimizer': 'sgd',
  72. 'base_lr': 0.12 / 64,
  73. 'backbone_lr_ratio': 1.0 / 3.0,
  74. 'momentum': 0.9,
  75. 'weight_decay': 1e-4,
  76. 'clip_max_norm': 10.0,
  77. 'param_dict_type': 'default',
  78. ## LR Scheduler
  79. 'lr_scheduler': 'step',
  80. 'warmup': 'linear',
  81. 'warmup_iters': 1500,
  82. 'warmup_factor': 0.00066667,
  83. ## Epoch
  84. 'max_epoch': 12, # 1x
  85. 'lr_epoch': [8, 11], # 1x
  86. # ----------------- Input -----------------
  87. ## Transforms
  88. 'train_min_size': [800], # short edge of image
  89. 'train_max_size': 1333,
  90. 'test_min_size': [800],
  91. 'test_max_size': 1333,
  92. ## Pixel mean & std
  93. 'pixel_mean': [0.485, 0.456, 0.406],
  94. 'pixel_std': [0.229, 0.224, 0.225],
  95. ## Transforms
  96. 'detr_style': False,
  97. 'trans_config': [
  98. {'name': 'RandomHFlip'},
  99. {'name': 'RandomResize'},
  100. {'name': 'RandomShift', 'max_shift': 32},
  101. ],
  102. 'box_format': 'xyxy',
  103. 'normalize_coords': False,
  104. },
  105. 'yolof_r50_c5_1x':{
  106. # ----------------- Model-----------------
  107. ## Backbone
  108. 'backbone': 'resnet50',
  109. 'backbone_norm': 'FrozeBN',
  110. 'res5_dilation': False,
  111. 'pretrained': True,
  112. 'pretrained_weight': 'imagenet1k_v1',
  113. 'freeze_at': 1, # freeze stem layer + layer1 of the backbone
  114. 'max_stride': 32,
  115. 'out_stride': 32,
  116. ## Neck
  117. 'neck': 'dilated_encoder',
  118. 'neck_dilations': [2, 4, 6, 8],
  119. 'neck_expand_ratio': 0.25,
  120. 'neck_act': 'relu',
  121. 'neck_norm': 'BN',
  122. ## Head
  123. 'head': 'yolof_head',
  124. 'head_dim': 512,
  125. 'num_cls_head': 2,
  126. 'num_reg_head': 4,
  127. 'head_act': 'relu',
  128. 'head_norm': 'BN',
  129. 'center_clamp': 32,
  130. 'anchor_size': [[32, 32], [64, 64], [128, 128], [256, 256], [512, 512]],
  131. ## Post-process
  132. 'train_topk': 1000,
  133. 'train_conf_thresh': 0.05,
  134. 'train_nms_thresh': 0.6,
  135. 'test_topk': 300,
  136. 'test_conf_thresh': 0.3,
  137. 'test_nms_thresh': 0.45,
  138. 'nms_class_agnostic': True, # We prefer to use class-agnostic NMS in the demo.
  139. # ----------------- Label Assignment -----------------
  140. 'matcher': 'yolof_matcher',
  141. 'matcher_hpy': {'topk_candidates': 4,
  142. 'iou_thresh': 0.15,
  143. 'ignore_thresh': 0.7,
  144. },
  145. # ----------------- Loss weight -----------------
  146. ## Loss hyper-parameters
  147. 'focal_loss_alpha': 0.25,
  148. 'focal_loss_gamma': 2.0,
  149. 'loss_cls_weight': 1.0,
  150. 'loss_reg_weight': 1.0,
  151. # ----------------- Training -----------------
  152. ## Training scheduler
  153. 'scheduler': '1x',
  154. ## Optimizer
  155. 'optimizer': 'sgd',
  156. 'base_lr': 0.12 / 64,
  157. 'backbone_lr_ratio': 1.0 / 3.0,
  158. 'momentum': 0.9,
  159. 'weight_decay': 1e-4,
  160. 'clip_max_norm': 10.0,
  161. 'param_dict_type': 'default',
  162. ## LR Scheduler
  163. 'lr_scheduler': 'step',
  164. 'warmup': 'linear',
  165. 'warmup_iters': 1500,
  166. 'warmup_factor': 0.00066667,
  167. ## Epoch
  168. 'max_epoch': 12, # 1x
  169. 'lr_epoch': [8, 11], # 1x
  170. # ----------------- Input -----------------
  171. ## Transforms
  172. 'train_min_size': [800], # short edge of image
  173. 'train_max_size': 1333,
  174. 'test_min_size': [800],
  175. 'test_max_size': 1333,
  176. ## Pixel mean & std
  177. 'pixel_mean': [0.485, 0.456, 0.406],
  178. 'pixel_std': [0.229, 0.224, 0.225],
  179. ## Transforms
  180. 'detr_style': False,
  181. 'trans_config': [
  182. {'name': 'RandomHFlip'},
  183. {'name': 'RandomResize'},
  184. {'name': 'RandomShift', 'max_shift': 32},
  185. ],
  186. 'box_format': 'xyxy',
  187. 'normalize_coords': False,
  188. },
  189. # --------------- Dilated C5 level ---------------
  190. 'yolof_r50_dc5_1x':{
  191. # ----------------- Model-----------------
  192. ## Backbone
  193. 'backbone': 'resnet50',
  194. 'backbone_norm': 'FrozeBN',
  195. 'res5_dilation': True,
  196. 'pretrained': True,
  197. 'pretrained_weight': 'imagenet1k_v1',
  198. 'freeze_at': 1, # freeze stem layer + layer1 of the backbone
  199. 'max_stride': 16,
  200. 'out_stride': 16,
  201. ## Neck
  202. 'neck': 'dilated_encoder',
  203. 'neck_dilations': [4, 8, 12, 16],
  204. 'neck_expand_ratio': 0.25,
  205. 'neck_act': 'relu',
  206. 'neck_norm': 'BN',
  207. ## Head
  208. 'head': 'yolof_head',
  209. 'head_dim': 512,
  210. 'num_cls_head': 2,
  211. 'num_reg_head': 4,
  212. 'head_act': 'relu',
  213. 'head_norm': 'BN',
  214. 'center_clamp': 32,
  215. 'anchor_size': [[16, 16], [32, 32], [64, 64], [128, 128], [256, 256], [512, 512]],
  216. ## Post-process
  217. 'train_topk': 1000,
  218. 'train_conf_thresh': 0.05,
  219. 'train_nms_thresh': 0.6,
  220. 'test_topk': 300,
  221. 'test_conf_thresh': 0.3,
  222. 'test_nms_thresh': 0.45,
  223. 'nms_class_agnostic': True, # We prefer to use class-agnostic NMS in the demo.
  224. # ----------------- Label Assignment -----------------
  225. 'matcher': 'yolof_matcher',
  226. 'matcher_hpy': {'topk_candidates': 8,
  227. 'iou_thresh': 0.1,
  228. 'ignore_thresh': 0.7,
  229. },
  230. # ----------------- Loss weight -----------------
  231. ## Loss hyper-parameters
  232. 'focal_loss_alpha': 0.25,
  233. 'focal_loss_gamma': 2.0,
  234. 'loss_cls_weight': 1.0,
  235. 'loss_reg_weight': 1.0,
  236. # ----------------- Training -----------------
  237. ## Training scheduler
  238. 'scheduler': '1x',
  239. ## Optimizer
  240. 'optimizer': 'sgd',
  241. 'base_lr': 0.12 / 64,
  242. 'backbone_lr_ratio': 1.0 / 3.0,
  243. 'momentum': 0.9,
  244. 'weight_decay': 1e-4,
  245. 'clip_max_norm': 10.0,
  246. 'param_dict_type': 'default',
  247. ## LR Scheduler
  248. 'lr_scheduler': 'step',
  249. 'warmup': 'linear',
  250. 'warmup_iters': 1500,
  251. 'warmup_factor': 0.00066667,
  252. ## Epoch
  253. 'max_epoch': 12, # 1x
  254. 'lr_epoch': [8, 11], # 1x
  255. # ----------------- Input -----------------
  256. ## Transforms
  257. 'train_min_size': [800], # short edge of image
  258. 'train_max_size': 1333,
  259. 'test_min_size': [800],
  260. 'test_max_size': 1333,
  261. ## Pixel mean & std
  262. 'pixel_mean': [0.485, 0.456, 0.406],
  263. 'pixel_std': [0.229, 0.224, 0.225],
  264. ## Transforms
  265. 'detr_style': False,
  266. 'trans_config': [
  267. {'name': 'RandomHFlip'},
  268. {'name': 'RandomResize'},
  269. {'name': 'RandomShift', 'max_shift': 32},
  270. ],
  271. 'box_format': 'xyxy',
  272. 'normalize_coords': False,
  273. },
  274. }