File size: 1,092 Bytes
271f3e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Rewrite portable relative image paths to absolute paths under EVAL_ROOT."""
import argparse
import json
import os
from pathlib import Path

IMAGE_KEYS = ("ref_image_path", "ref_obj_image_path", "pasted_image")


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--eval-root", type=Path, required=True)
    ap.add_argument("--input", type=Path, required=True)
    ap.add_argument("--output", type=Path, required=True)
    args = ap.parse_args()

    root = args.eval_root.resolve()
    with open(args.input, encoding="utf-8") as f:
        data = json.load(f)

    for item in data:
        for key in IMAGE_KEYS:
            val = item.get(key)
            if val and isinstance(val, str) and not os.path.isabs(val):
                item[key] = str((root / val).resolve())

    args.output.parent.mkdir(parents=True, exist_ok=True)
    with open(args.output, "w", encoding="utf-8") as f:
        json.dump(data, f, ensure_ascii=False, indent=2)
    print(f"[absolutize] {args.output} ({len(data)} samples)")


if __name__ == "__main__":
    main()