Skip to content

Commit

Permalink
Modify tuner best.pt logic to train first (ultralytics#8792)
Browse files Browse the repository at this point in the history
  • Loading branch information
finlaymorrison authored and hmurari committed Apr 17, 2024
1 parent 9dc2388 commit e84c5e7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ultralytics/engine/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit e84c5e7

Please sign in to comment.