#!/usr/bin/env python3 """Run one image group or a complete scene through one persistent pipeline.""" import argparse import json from pathlib import Path import sys from syncfix_h100._r03 import _a033 as load_images, _a041 as request_rows from syncfix_h100._r02 import _a048 as validate_seed def main(): parser = argparse.ArgumentParser(description="SyncFix H100: three degraded views and one reference") parser.add_argument("--bundle", type=Path, default=Path(__file__).resolve().parent) group = parser.add_mutually_exclusive_group(required=True) group.add_argument("--degraded", nargs=3, metavar="IMAGE") group.add_argument("--requests", type=Path, help="JSONL or JSON array of scene groups") parser.add_argument("--reference", type=Path) parser.add_argument("--seed", type=int) parser.add_argument("--output-dir", type=Path, required=True) parser.add_argument("--trt-lib-dir", type=Path) parser.add_argument("--lock-timeout", type=float, default=0) args = parser.parse_args() if args.degraded: if args.reference is None: parser.error("--reference is required with --degraded") validate_seed(args.seed) rows = [{"id": "result", "degraded": args.degraded, "reference": args.reference, "seed": args.seed}] else: if args.reference is not None or args.seed is not None: parser.error("Put reference and seed in each request record when using --requests") rows = request_rows(args.requests) out = args.output_dir.expanduser().resolve() if out.exists() and (not out.is_dir() or any(out.iterdir())): raise FileExistsError("Choose a new or empty output directory") # Validate the first input before loading the GPU model. first_images = load_images(rows[0]["degraded"], rows[0]["reference"]) out.mkdir(parents=True, exist_ok=True) from syncfix_h100 import Pipeline with Pipeline(args.bundle, trt_lib_dir=args.trt_lib_dir, lock_timeout=args.lock_timeout) as pipeline: with (out / "requests.jsonl").open("x") as journal: for index, row in enumerate(rows): images = first_images if index == 0 else load_images(row["degraded"], row["reference"]) outputs = pipeline.infer(images[:3], images[3], seed=row.get("seed")) folder = out / row["id"] folder.mkdir() paths = [] for number, image in enumerate(outputs): path = folder / f"output_{number}.png" image.save(path) paths.append(str(path)) record = {"id": row["id"], "outputs": paths, "seed": row.get("seed")} journal.write(json.dumps(record) + "\n") journal.flush() print(json.dumps(record), flush=True) if __name__ == "__main__": try: main() except (ValueError, OSError, RuntimeError) as error: print(f"SyncFix: {error}", file=sys.stderr) raise SystemExit(1)