yolov1_config.py 3.0 KB

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