yolof_config.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.batch_size_base = 64
  62. self.per_image_lr = 0.12 / 64
  63. self.bk_lr_ratio = 1.0 / 3.0
  64. self.momentum = 0.9
  65. self.weight_decay = 1e-4
  66. self.clip_max_norm = 10.0
  67. # --------- LR Scheduler ---------
  68. self.lr_scheduler = 'step'
  69. self.warmup = 'linear'
  70. self.warmup_iters = 1500
  71. self.warmup_factor = 0.00066667
  72. # --------- Train epoch ---------
  73. self.max_epoch = 12 # 1x
  74. self.lr_epoch = [8, 11] # 1x
  75. self.eval_epoch = 2
  76. # --------- Data process ---------
  77. ## input size
  78. self.train_min_size = [800] # short edge of image
  79. self.train_max_size = 1333
  80. self.test_min_size = [320]
  81. self.test_max_size = 320
  82. ## Pixel mean & std
  83. self.pixel_mean = [0.485, 0.456, 0.406]
  84. self.pixel_std = [0.229, 0.224, 0.225]
  85. ## Transforms
  86. self.box_format = 'xyxy'
  87. self.normalize_coords = False
  88. self.detr_style = False
  89. self.trans_config = [
  90. {'name': 'RandomHFlip'},
  91. {'name': 'RandomResize'},
  92. {'name': 'RandomShift', 'max_shift': 32},
  93. ]
  94. def print_config(self):
  95. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  96. for k, v in config_dict.items():
  97. print("{} : {}".format(k, v))
  98. class Yolof_R18_C5_1x_Config(YolofBaseConfig):
  99. def __init__(self) -> None:
  100. super().__init__()
  101. ## Backbone
  102. # --------- Backbone ---------
  103. self.backbone = "resnet18"
  104. class Yolof_R50_C5_1x_Config(YolofBaseConfig):
  105. def __init__(self) -> None:
  106. super().__init__()
  107. ## Backbone
  108. # --------- Backbone ---------
  109. self.backbone = "resnet50"
  110. class Yolof_R50_DC5_1x_Config(YolofBaseConfig):
  111. def __init__(self) -> None:
  112. super().__init__()
  113. ## Backbone
  114. # --------- Backbone ---------
  115. self.backbone = "resnet50"
  116. self.res5_dilation = True
  117. self.use_pretrained = True
  118. self.max_stride = 16
  119. self.out_stride = 16
  120. # --------- Neck ---------
  121. self.neck = 'dilated_encoder'
  122. self.neck_dilations = [4, 8, 12, 16]
  123. self.neck_expand_ratio = 0.25
  124. self.neck_act = 'relu'
  125. self.neck_norm = 'GN'
  126. # --------- Head ---------
  127. self.anchor_size = [[16, 16],
  128. [32, 32],
  129. [64, 64],
  130. [128, 128],
  131. [256, 256],
  132. [512, 512]],
  133. # --------- Label Assignment ---------
  134. self.matcher = 'yolof_matcher'
  135. self.matcher_hpy = {'topk_candidates': 8,
  136. 'iou_thresh': 0.1,
  137. 'ignore_thresh': 0.7,
  138. }