Gate completed checkpoints through training loop
This commit is contained in:
@@ -191,6 +191,11 @@ def main() -> int:
|
||||
parser.add_argument("--min-region-recall", type=float, default=0.4)
|
||||
parser.add_argument("--max-pure-empty-fp", type=int, default=0)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
parser.add_argument(
|
||||
"--evaluate-initial-model",
|
||||
action="store_true",
|
||||
help="Gate an already trained initial checkpoint before starting the next training iteration.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
if args.iterations < 1:
|
||||
raise SystemExit("--iterations must be positive")
|
||||
@@ -223,7 +228,8 @@ def main() -> int:
|
||||
name = f"iteration-{index:03d}"
|
||||
iteration_dir = args.output_dir / name
|
||||
train_run = args.output_dir / "runs" / name
|
||||
command = training_command(
|
||||
evaluate_existing = args.evaluate_initial_model and offset == 0 and not state["iterations"]
|
||||
command = None if evaluate_existing else training_command(
|
||||
args.yolo,
|
||||
model=model,
|
||||
data=train_yaml,
|
||||
@@ -242,12 +248,18 @@ def main() -> int:
|
||||
translate=args.translate,
|
||||
)
|
||||
if args.dry_run:
|
||||
print(json.dumps({"training_command": command}, indent=2))
|
||||
print(json.dumps({"training_command": command, "evaluate_existing": evaluate_existing}, indent=2))
|
||||
return 0
|
||||
run(command, iteration_dir / "training.log")
|
||||
best = train_run / "weights" / "best.pt"
|
||||
if not best.is_file():
|
||||
raise RuntimeError(f"Training produced no best checkpoint: {best}")
|
||||
if evaluate_existing:
|
||||
best = model
|
||||
if not best.is_file():
|
||||
raise RuntimeError(f"Initial checkpoint does not exist: {best}")
|
||||
else:
|
||||
assert command is not None
|
||||
run(command, iteration_dir / "training.log")
|
||||
best = train_run / "weights" / "best.pt"
|
||||
if not best.is_file():
|
||||
raise RuntimeError(f"Training produced no best checkpoint: {best}")
|
||||
candidate = iteration_dir / "candidate.pt"
|
||||
shutil.copy2(best, candidate)
|
||||
|
||||
@@ -347,6 +359,7 @@ def main() -> int:
|
||||
"iteration": index,
|
||||
"candidate": str(candidate),
|
||||
"candidate_sha256": sha256(candidate),
|
||||
"training_skipped_for_existing_checkpoint": evaluate_existing,
|
||||
"assessment": str(assessment),
|
||||
"status": decision["status"],
|
||||
"failures": decision["failures"],
|
||||
|
||||
Reference in New Issue
Block a user