From e6d3f63086fb3dca55e87f5c88ee35a7bd93669b Mon Sep 17 00:00:00 2001 From: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Date: Tue, 11 Mar 2025 01:50:42 +0800 Subject: [PATCH] Revert `shell=True` for `model.tune()` (#19625) Signed-off-by: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Co-authored-by: UltralyticsAssistant --- ultralytics/engine/tuner.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ultralytics/engine/tuner.py b/ultralytics/engine/tuner.py index 4c8e25d8..13cb740d 100644 --- a/ultralytics/engine/tuner.py +++ b/ultralytics/engine/tuner.py @@ -191,8 +191,9 @@ class Tuner: weights_dir = save_dir / "weights" 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(" ".join(cmd), check=True, shell=True).returncode + launch = [__import__("sys").executable, "-m", "ultralytics.cfg.__init__"] # workaround yolo not found + cmd = [*launch, "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"