yolov1_config.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # yolo Config
  2. def build_yolov1_config(args):
  3. if args.model == 'yolov1_r18':
  4. return Yolov1R18Config()
  5. else:
  6. raise NotImplementedError("No config for model: {}".format(args.model))
  7. # YOLOv1-Base config
  8. class Yolov1BaseConfig(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. # ---------------- Post-process config ----------------
  30. ## Post process
  31. self.val_topk = 1000
  32. self.val_conf_thresh = 0.001
  33. self.val_nms_thresh = 0.7
  34. self.test_topk = 300
  35. self.test_conf_thresh = 0.4
  36. self.test_nms_thresh = 0.5
  37. # ---------------- Assignment config ----------------
  38. ## Loss weight
  39. self.loss_obj = 1.0
  40. self.loss_cls = 1.0
  41. self.loss_box = 5.0
  42. # ---------------- ModelEMA config ----------------
  43. self.use_ema = True
  44. self.ema_decay = 0.9998
  45. self.ema_tau = 2000
  46. # ---------------- Optimizer config ----------------
  47. self.trainer = 'yolo'
  48. self.optimizer = 'adamw'
  49. self.per_image_lr = 0.001 / 64
  50. self.base_lr = None # base_lr = per_image_lr * batch_size
  51. self.min_lr_ratio = 0.01 # min_lr = base_lr * min_lr_ratio
  52. self.momentum = 0.9
  53. self.weight_decay = 0.05
  54. self.clip_max_norm = 35.0
  55. self.warmup_bias_lr = 0.1
  56. self.warmup_momentum = 0.8
  57. # ---------------- Lr Scheduler config ----------------
  58. self.warmup_epoch = 3
  59. self.lr_scheduler = "linear"
  60. self.max_epoch = 150
  61. self.eval_epoch = 10
  62. self.no_aug_epoch = 20
  63. # ---------------- Data process config ----------------
  64. self.aug_type = 'ssd'
  65. self.box_format = 'xyxy'
  66. self.normalize_coords = False
  67. self.mosaic_prob = 0.0
  68. self.mixup_prob = 0.0
  69. self.copy_paste = 0.0 # approximated by the YOLOX's mixup
  70. self.multi_scale = [0.5, 1.25] # multi scale: [img_size * 0.5, img_size * 1.5]
  71. ## Pixel mean & std
  72. self.pixel_mean = [123.675, 116.28, 103.53] # RGB format
  73. self.pixel_std = [58.395, 57.12, 57.375] # RGB format
  74. ## Transforms
  75. self.train_img_size = 640
  76. self.test_img_size = 640
  77. def print_config(self):
  78. config_dict = {key: value for key, value in self.__dict__.items() if not key.startswith('__')}
  79. for k, v in config_dict.items():
  80. print("{} : {}".format(k, v))
  81. # YOLOv1-R18
  82. class Yolov1R18Config(Yolov1BaseConfig):
  83. def __init__(self) -> None:
  84. super().__init__()
  85. self.backbone = 'resnet18'
  86. # YOLOv1-R50
  87. class Yolov1R50Config(Yolov1BaseConfig):
  88. def __init__(self) -> None:
  89. super().__init__()
  90. # TODO: Try your best.