From 57a63d9468851beb512f1c8121e387d64d3baada Mon Sep 17 00:00:00 2001 From: Finlay Morrison <57669260+finlaymorrison@users.noreply.github.com> Date: Fri, 8 Mar 2024 14:57:12 +0000 Subject: [PATCH] Modify tuner best.pt logic to train first (#8792) --- ultralytics/engine/tuner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultralytics/engine/tuner.py b/ultralytics/engine/tuner.py index de804fd0ee1..a009e73abf3 100644 --- a/ultralytics/engine/tuner.py +++ b/ultralytics/engine/tuner.py @@ -188,11 +188,11 @@ def __call__(self, model=None, iterations=10, cleanup=True): train_args = {**vars(self.args), **mutated_hyp} save_dir = get_save_dir(get_cfg(train_args)) weights_dir = save_dir / "weights" - ckpt_file = weights_dir / ("best.pt" if (weights_dir / "best.pt").exists() else "last.pt") try: # Train YOLO model with mutated hyperparameters (run in subprocess to avoid dataloader hang) cmd = ["yolo", "train", *(f"{k}={v}" for k, v in train_args.items())] return_code = subprocess.run(cmd, check=True).returncode + ckpt_file = weights_dir / ("best.pt" if (weights_dir / "best.pt").exists() else "last.pt") metrics = torch.load(ckpt_file)["train_metrics"] assert return_code == 0, "training failed"