Image-to-Image
TensorRT
h100
syncfix
File size: 3,028 Bytes
708d7f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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)