yolof_config.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # You Only Look One-level Feature
  2. def build_yolof_config(args):
  3. if args.model == 'yolof_r18_c5_1x':
  4. return Yolof_R18_C5_1x_Config()
  5. elif args.model == 'yolof_r50_c5_1x':
  6. return Yolof_R50_C5_1x_Config()
  7. elif args.model == 'yolof_r101_c5_1x':
  8. return Yolof_R101_C5_1x_Config()
  9. elif args.model == 'yolof_r50_dc5_1x':
  10. return Yolof_R50_DC5_1x_Config()
  11. elif args.model == 'yolof_r101_dc5_1x':
  12. return Yolof_R101_DC5_1x_Config()
  13. else:
  14. raise NotImplementedError("No config for model: {}".format(args.model))
  15. # --------------- Base configuration ---------------
  16. class YolofBaseConfig(object):
  17. def __init__(self):
  18. # --------- Backbone ---------
  19. self.backbone = "resnet50"
  20. self.bk_norm = "FrozeBN"
  21. self.res5_dilation = False
  22. self.use_pretrained = True
  23. self.freeze_at = 1
  24. self.max_stride = 32
  25. self.out_stride = 32
  26. # --------- Neck ---------
  27. self.neck = 'dilated_encoder'
  28. self.neck_dilations = [2, 4, 6, 8]
  29. self.neck_expand_ratio = 0.25
  30. self.neck_act = 'relu'
  31. self.neck_norm = 'BN'
  32. # --------- Head ---------
  33. self.head = 'yolof_head'
  34. self.head_dim = 512
  35. self.num_cls_head = 2
  36. self.num_reg_head = 4
  37. self.head_act = 'relu'
  38. self.head_norm = 'BN'
  39. self.center_clamp = 32
  40. self.anchor_size = [[32, 32],
  41. [64, 64],
  42. [128, 128],
  43. [256, 256],
  44. [512, 512]]
  45. # --------- Post-process ---------
  46. self.train_topk = 1000
  47. self.train_conf_thresh = 0.05
  48. self.train_nms_thresh = 0.6
  49. self.test_topk = 300
  50. self.test_conf_thresh = 0.3
  51. self.test_nms_thresh = 0.45
  52. self.nms_class_agnostic = True
  53. # --------- Label Assignment ---------
  54. self.matcher = 'yolof_matcher'
  55. self.matcher_hpy = {'topk_candidates': 4,
  56. 'iou_thresh': 0.15,
  57. 'ignore_thresh': 0.7,
  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. # --------- Optimizer ---------
  65. self.optimizer = 'sgd'
  66. self.batch_size_base = 64
  67. self.per_image_lr = 0.12 / 64
  68. self.bk_lr_ratio = 1.0 / 3.0
  69. self.momentum = 0.9
  70. self.weight_decay = 1e-4
  71. self.clip_max_norm = 10.0
  72. # --------- LR Scheduler ---------
  73. self.lr_scheduler = 'step'
  74. self.warmup = 'linear'
  75. self.warmup_iters = 1500
  76. self.warmup_factor = 0.00066667
  77. # --------- Train epoch ---------
  78. self.max_epoch = 12 # 1x
  79. self.lr_epoch = [8, 11] # 1x
  80. self.eval_epoch = 2
  81. # --------- Data process ---------
  82. self.use_coco_labels_91 = False
  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. {'name': 'RandomShift', 'max_shift': 32},
  99. ]
  100. def print_config(self):
  101. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  102. for k, v in config_dict.items():
  103. print("{} : {}".format(k, v))
  104. # --------------- C5 level & 1x scheduler ---------------
  105. class Yolof_R18_C5_1x_Config(YolofBaseConfig):
  106. def __init__(self) -> None:
  107. super().__init__()
  108. ## Backbone
  109. # --------- Backbone ---------
  110. self.backbone = "resnet18"
  111. class Yolof_R50_C5_1x_Config(Yolof_R18_C5_1x_Config):
  112. def __init__(self) -> None:
  113. super().__init__()
  114. ## Backbone
  115. # --------- Backbone ---------
  116. self.backbone = "resnet50"
  117. class Yolof_R101_C5_1x_Config(Yolof_R18_C5_1x_Config):
  118. def __init__(self) -> None:
  119. super().__init__()
  120. ## Backbone
  121. # --------- Backbone ---------
  122. self.backbone = "resnet101"
  123. # --------------- DC5 level & 1x scheduler ---------------
  124. class Yolof_R50_DC5_1x_Config(YolofBaseConfig):
  125. def __init__(self) -> None:
  126. super().__init__()
  127. ## Backbone
  128. # --------- Backbone ---------
  129. self.backbone = "resnet50"
  130. self.res5_dilation = True
  131. self.use_pretrained = True
  132. self.max_stride = 16
  133. self.out_stride = 16
  134. # --------- Neck ---------
  135. self.neck = 'dilated_encoder'
  136. self.neck_dilations = [4, 8, 12, 16]
  137. self.neck_expand_ratio = 0.25
  138. self.neck_act = 'relu'
  139. self.neck_norm = 'BN'
  140. # --------- Head ---------
  141. self.anchor_size = [[16, 16],
  142. [32, 32],
  143. [64, 64],
  144. [128, 128],
  145. [256, 256],
  146. [512, 512]],
  147. # --------- Label Assignment ---------
  148. self.matcher = 'yolof_matcher'
  149. self.matcher_hpy = {'topk_candidates': 8,
  150. 'iou_thresh': 0.1,
  151. 'ignore_thresh': 0.7,
  152. }
  153. class Yolof_R101_DC5_1x_Config(Yolof_R50_DC5_1x_Config):
  154. def __init__(self) -> None:
  155. super().__init__()
  156. # --------- Backbone ---------
  157. self.backbone = "resnet101"