yolof_config.py 8.9 KB

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