yolov2_config.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. ## Head
  17. self.head_dim = 512
  18. self.num_cls_head = 2
  19. self.num_reg_head = 2
  20. self.anchor_sizes = [[17, 25], [55, 75], [92, 206], [202, 21], [289, 311]]
  21. # ---------------- Post-process config ----------------
  22. ## Post process
  23. self.val_topk = 1000
  24. self.val_conf_thresh = 0.001
  25. self.val_nms_thresh = 0.7
  26. self.test_topk = 300
  27. self.test_conf_thresh = 0.3
  28. self.test_nms_thresh = 0.5
  29. # ---------------- Assignment config ----------------
  30. ## Matcher
  31. self.iou_thresh = 0.5
  32. ## Loss weight
  33. self.loss_obj = 1.0
  34. self.loss_cls = 1.0
  35. self.loss_box = 5.0
  36. # ---------------- ModelEMA config ----------------
  37. self.use_ema = True
  38. self.ema_decay = 0.9998
  39. self.ema_tau = 2000
  40. # ---------------- Optimizer config ----------------
  41. self.trainer = 'yolo'
  42. self.optimizer = 'adamw'
  43. self.base_lr = 0.001 # base_lr = per_image_lr * batch_size
  44. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  45. self.batch_size_base = 64
  46. self.momentum = 0.9
  47. self.weight_decay = 0.05
  48. self.clip_max_norm = 35.0
  49. self.warmup_bias_lr = 0.1
  50. self.warmup_momentum = 0.8
  51. # ---------------- Lr Scheduler config ----------------
  52. self.warmup_epoch = 3
  53. self.lr_scheduler = "cosine"
  54. self.max_epoch = 150
  55. self.eval_epoch = 10
  56. self.no_aug_epoch = -1
  57. # ---------------- Data process config ----------------
  58. self.aug_type = 'ssd'
  59. self.mosaic_prob = 0.0
  60. self.mixup_prob = 0.0
  61. self.copy_paste = 0.0 # approximated by the YOLOX's mixup
  62. self.multi_scale = [0.5, 1.25] # multi scale: [img_size * 0.5, img_size * 1.5]
  63. ## Pixel mean & std
  64. self.pixel_mean = [123.675, 116.28, 103.53] # RGB format
  65. self.pixel_std = [58.395, 57.12, 57.375] # RGB format
  66. ## Transforms
  67. self.train_img_size = 640
  68. self.test_img_size = 640
  69. self.affine_params = None
  70. def print_config(self):
  71. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  72. for k, v in config_dict.items():
  73. print("{} : {}".format(k, v))
  74. # YOLOv2-R18
  75. class Yolov2R18Config(Yolov2BaseConfig):
  76. def __init__(self) -> None:
  77. super().__init__()
  78. self.backbone = 'resnet18'
  79. # YOLOv2-R50
  80. class Yolov2R50Config(Yolov2BaseConfig):
  81. def __init__(self) -> None:
  82. super().__init__()
  83. # TODO: Try your best.