yolof_config.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_r50_dc5_1x':
  8. return Yolof_R50_DC5_1x_Config()
  9. else:
  10. raise NotImplementedError("No config for model: {}".format(args.model))
  11. class YolofBaseConfig(object):
  12. def __init__(self):
  13. # --------- Backbone ---------
  14. self.backbone = "resnet50"
  15. self.bk_norm = "FrozeBN"
  16. self.res5_dilation = False
  17. self.use_pretrained = True
  18. self.freeze_at = 1
  19. self.max_stride = 32
  20. self.out_stride = 32
  21. # --------- Neck ---------
  22. self.neck = 'dilated_encoder'
  23. self.neck_dilations = [2, 4, 6, 8]
  24. self.neck_expand_ratio = 0.25
  25. self.neck_act = 'relu'
  26. self.neck_norm = 'GN'
  27. # --------- Head ---------
  28. self.head = 'yolof_head'
  29. self.head_dim = 512
  30. self.num_cls_head = 2
  31. self.num_reg_head = 4
  32. self.head_act = 'relu'
  33. self.head_norm = 'GN'
  34. self.center_clamp = 32,
  35. self.anchor_size = [[32, 32],
  36. [64, 64],
  37. [128, 128],
  38. [256, 256],
  39. [512, 512]],
  40. # --------- Post-process ---------
  41. self.train_topk = 1000
  42. self.train_conf_thresh = 0.05
  43. self.train_nms_thresh = 0.6
  44. self.test_topk = 300
  45. self.test_conf_thresh = 0.3
  46. self.test_nms_thresh = 0.45
  47. self.nms_class_agnostic = True
  48. # --------- Label Assignment ---------
  49. self.matcher = 'yolof_matcher'
  50. self.matcher_hpy = {'topk_candidates': 4,
  51. 'iou_thresh': 0.15,
  52. 'ignore_thresh': 0.7,
  53. }
  54. # --------- Loss weight ---------
  55. self.focal_loss_alpha = 0.25
  56. self.focal_loss_gamma = 2.0
  57. self.loss_cls_weight = 1.0
  58. self.loss_reg_weight = 1.0
  59. # --------- Optimizer ---------
  60. self.optimizer = 'sgd'
  61. self.per_image_lr = 0.12 / 64
  62. self.bk_lr_ratio = 1.0 / 3.0
  63. self.momentum = 0.9
  64. self.weight_decay = 1e-4
  65. self.clip_max_norm = 10.0
  66. # --------- LR Scheduler ---------
  67. self.lr_scheduler = 'step'
  68. self.warmup = 'linear'
  69. self.warmup_iters = 1500
  70. self.warmup_factor = 0.00066667
  71. # --------- Train epoch ---------
  72. self.max_epoch = 12, # 1x
  73. self.lr_epoch = [8, 11] # 1x
  74. # --------- Data process ---------
  75. ## input size
  76. self.train_min_size = [800] # short edge of image
  77. self.train_max_size = 1333
  78. self.test_min_size = [800]
  79. self.test_max_size = 1333
  80. ## Pixel mean & std
  81. self.pixel_mean = [0.485, 0.456, 0.406]
  82. self.pixel_std = [0.229, 0.224, 0.225]
  83. ## Transforms
  84. self.box_format = 'xyxy'
  85. self.normalize_coords = False
  86. self.detr_style = False
  87. self.trans_config = [
  88. {'name': 'RandomHFlip'},
  89. {'name': 'RandomResize'},
  90. {'name': 'RandomShift', 'max_shift': 32},
  91. ]
  92. def print_config(self):
  93. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  94. for k, v in config_dict.items():
  95. print("{} : {}".format(k, v))
  96. class Yolof_R18_C5_1x_Config(YolofBaseConfig):
  97. def __init__(self) -> None:
  98. super().__init__()
  99. ## Backbone
  100. # --------- Backbone ---------
  101. self.backbone = "resnet18"
  102. class Yolof_R50_C5_1x_Config(YolofBaseConfig):
  103. def __init__(self) -> None:
  104. super().__init__()
  105. ## Backbone
  106. # --------- Backbone ---------
  107. self.backbone = "resnet50"
  108. class Yolof_R50_DC5_1x_Config(YolofBaseConfig):
  109. def __init__(self) -> None:
  110. super().__init__()
  111. ## Backbone
  112. # --------- Backbone ---------
  113. self.backbone = "resnet50"
  114. self.res5_dilation = True
  115. self.use_pretrained = True
  116. self.max_stride = 16
  117. self.out_stride = 16
  118. # --------- Neck ---------
  119. self.neck = 'dilated_encoder'
  120. self.neck_dilations = [4, 8, 12, 16]
  121. self.neck_expand_ratio = 0.25
  122. self.neck_act = 'relu'
  123. self.neck_norm = 'GN'
  124. # --------- Head ---------
  125. self.anchor_size = [[16, 16],
  126. [32, 32],
  127. [64, 64],
  128. [128, 128],
  129. [256, 256],
  130. [512, 512]],
  131. # --------- Label Assignment ---------
  132. self.matcher = 'yolof_matcher'
  133. self.matcher_hpy = {'topk_candidates': 8,
  134. 'iou_thresh': 0.1,
  135. 'ignore_thresh': 0.7,
  136. }