yolov2_config.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # yolo Config
  2. def build_yolov2_config(args):
  3. if args.model == 'yolov2_r18':
  4. return Yolov2R18Config()
  5. else:
  6. raise NotImplementedError("No config for model: {}".format(args.model))
  7. # YOLOv2-Base config
  8. class Yolov2BaseConfig(object):
  9. def __init__(self) -> None:
  10. # ---------------- Model config ----------------
  11. self.out_stride = 32
  12. self.max_stride = 32
  13. ## Backbone
  14. self.backbone = 'resnet50'
  15. self.use_pretrained = True
  16. ## Neck
  17. self.neck_act = 'lrelu'
  18. self.neck_norm = 'BN'
  19. self.neck_depthwise = False
  20. self.neck_expand_ratio = 0.5
  21. self.spp_pooling_size = 5
  22. ## Head
  23. self.head_act = 'lrelu'
  24. self.head_norm = 'BN'
  25. self.head_depthwise = False
  26. self.head_dim = 512
  27. self.num_cls_head = 2
  28. self.num_reg_head = 2
  29. self.anchor_sizes = [[17, 25], [55, 75], [92, 206], [202, 21], [289, 311]]
  30. # ---------------- Post-process config ----------------
  31. ## Post process
  32. self.val_topk = 1000
  33. self.val_conf_thresh = 0.001
  34. self.val_nms_thresh = 0.7
  35. self.test_topk = 300
  36. self.test_conf_thresh = 0.4
  37. self.test_nms_thresh = 0.5
  38. # ---------------- Assignment config ----------------
  39. ## Matcher
  40. self.iou_thresh = 0.5
  41. ## Loss weight
  42. self.loss_obj = 1.0
  43. self.loss_cls = 1.0
  44. self.loss_box = 5.0
  45. # ---------------- ModelEMA config ----------------
  46. self.use_ema = True
  47. self.ema_decay = 0.9998
  48. self.ema_tau = 2000
  49. # ---------------- Optimizer config ----------------
  50. self.trainer = 'yolo'
  51. self.optimizer = 'adamw'
  52. self.per_image_lr = 0.001 / 64
  53. self.base_lr = None # base_lr = per_image_lr * batch_size
  54. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  55. self.momentum = 0.9
  56. self.weight_decay = 0.05
  57. self.clip_max_norm = 35.0
  58. self.warmup_bias_lr = 0.1
  59. self.warmup_momentum = 0.8
  60. # ---------------- Lr Scheduler config ----------------
  61. self.warmup_epoch = 3
  62. self.lr_scheduler = "cosine"
  63. self.max_epoch = 150
  64. self.eval_epoch = 10
  65. self.no_aug_epoch = -1
  66. # ---------------- Data process config ----------------
  67. self.aug_type = 'ssd'
  68. self.box_format = 'xyxy'
  69. self.normalize_coords = False
  70. self.mosaic_prob = 0.0
  71. self.mixup_prob = 0.0
  72. self.copy_paste = 0.0 # approximated by the YOLOX's mixup
  73. self.multi_scale = [0.5, 1.25] # multi scale: [img_size * 0.5, img_size * 1.5]
  74. ## Pixel mean & std
  75. self.pixel_mean = [123.675, 116.28, 103.53] # RGB format
  76. self.pixel_std = [58.395, 57.12, 57.375] # RGB format
  77. ## Transforms
  78. self.train_img_size = 640
  79. self.test_img_size = 640
  80. def print_config(self):
  81. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  82. for k, v in config_dict.items():
  83. print("{} : {}".format(k, v))
  84. # YOLOv2-R18
  85. class Yolov2R18Config(Yolov2BaseConfig):
  86. def __init__(self) -> None:
  87. super().__init__()
  88. self.backbone = 'resnet18'
  89. # YOLOv2-R50
  90. class Yolov2R50Config(Yolov2BaseConfig):
  91. def __init__(self) -> None:
  92. super().__init__()
  93. # TODO: Try your best.