Download scripts/absolutize_dataset_json.py from ProAudience/agenthoi-eval: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/datasets/ProAudience/agenthoi-eval/resolve/main/scripts/absolutize_dataset_json.py
- Command line
-
hf download hf://datasets/ProAudience/agenthoi-eval/scripts/absolutize_dataset_json.py
-
curl -L -o absolutize_dataset_json.py https://huggingface.co/datasets/ProAudience/agenthoi-eval/resolve/main/scripts/absolutize_dataset_json.py
1.09 kB
| #!/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() | |