Aperture-580 / tools /make_eval_jsonl.py
Skywalker0410's picture
Add files using upload-large-folder tool
53b15ef verified
Raw History Blame Contribute Delete
2.32 kB
#!/usr/bin/env python3
"""Materialize a flat evaluation jsonl with absolute image paths.
python tools/make_eval_jsonl.py --lang en --images ./images --out /tmp/ap580_en.jsonl
The output uses the field names a ZoomLynx-style runner expects (`bucket` for the
coarse label, `primary_type` for the fine label) and keeps the annotations.
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--lang", choices=["zh", "en", "bilingual"], default="en")
ap.add_argument("--images", default=str(ROOT / "images"))
ap.add_argument("--out", required=True)
args = ap.parse_args()
src = ROOT / "data" / f"aperture580_{args.lang}.jsonl"
rows = [json.loads(line) for line in src.read_text(encoding="utf-8").splitlines() if line.strip()]
images = Path(args.images).resolve()
out = Path(args.out)
out.parent.mkdir(parents=True, exist_ok=True)
with out.open("w", encoding="utf-8") as fh:
for row in rows:
if args.lang == "bilingual":
question, reference = row["question_zh"], row["reference_answer_zh"]
else:
question, reference = row["question"], row["reference_answer"]
fh.write(json.dumps({
"sample_id": row["sample_id"],
"image": str(images / row["image"]),
"question": question,
"reference_answer": reference,
"question_type": row["question_type"],
"bucket": row["label_coarse"],
"primary_type": row["label_fine"],
"minimum_calls": row["minimum_calls"],
"maximum_useful_calls": row["maximum_useful_calls"],
"oracle_region_0_1000": row["oracle_region_0_1000"],
"oracle_regions_aux": row["oracle_regions_aux"],
}, ensure_ascii=False) + "\n")
missing = [r["image"] for r in rows if not (images / r["image"]).is_file()]
print(f"wrote {out} rows={len(rows)} images_dir={images} missing_images={len(missing)}")
if missing:
print("first missing:", missing[:3])
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())