Download scripts/_full_trace_dump.py from LiYacheng/r4d-bench-qa: direct link, hf CLI and curl.
- Browser
- Download file 3.5 kB
-
https://huggingface.co/datasets/LiYacheng/r4d-bench-qa/resolve/main/scripts/_full_trace_dump.py
- Command line
-
hf download hf://datasets/LiYacheng/r4d-bench-qa/scripts/_full_trace_dump.py
-
curl -L -o _full_trace_dump.py https://huggingface.co/datasets/LiYacheng/r4d-bench-qa/resolve/main/scripts/_full_trace_dump.py
3.5 kB
| """Dump COCO categories / tracks / queries per scene for full-pipeline trace review.""" | |
| from __future__ import annotations | |
| import csv | |
| import json | |
| import sys | |
| from collections import Counter, defaultdict | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from scripts.predictions_ground_truth import SCENES_CONFIG, frame_number_from_coco_image | |
| OUT = ROOT / "assets" / "gt_audit" / "full_trace" | |
| OUT.mkdir(parents=True, exist_ok=True) | |
| def load(p): | |
| return json.loads(Path(p).read_text(encoding="utf-8")) | |
| def main(): | |
| csv_rows = list(csv.DictReader((ROOT / "data/track_metadata.csv").open(encoding="utf-8"))) | |
| csv_by_tid = {r["track_id"]: r for r in csv_rows} | |
| lines = [] | |
| for cfg in SCENES_CONFIG: | |
| sd = ROOT / "data/scenes" / cfg["folder"] | |
| coco = load(sd / cfg["annot_file"]) | |
| tracks = load(sd / cfg["track_file"])["tracks"] | |
| qs = load(sd / cfg["query_file"]) | |
| if isinstance(qs, dict): | |
| qs = qs["queries"] | |
| cats = {c["id"]: c["name"] for c in coco["categories"]} | |
| fids = sorted( | |
| int(f) for f in (frame_number_from_coco_image(im) for im in coco["images"]) if f is not None | |
| ) | |
| per_img_cat = defaultdict(Counter) | |
| for a in coco["annotations"]: | |
| per_img_cat[a["image_id"]][a["category_id"]] += 1 | |
| ann_count = Counter(a["category_id"] for a in coco["annotations"]) | |
| max_per_img = Counter() | |
| img_presence = Counter() | |
| for im_id, c in per_img_cat.items(): | |
| for cid, n in c.items(): | |
| max_per_img[cid] = max(max_per_img[cid], n) | |
| img_presence[cid] += 1 | |
| lines.append(f"\n################ {cfg['folder']} annot={cfg['annot_file']}") | |
| lines.append(f"images={len(coco['images'])} frames={fids[:6]}..{fids[-3:]} n={len(fids)}") | |
| lines.append(f"curated36={cfg['queries']}") | |
| lines.append("-- COCO categories (id name anns imgs max_per_img)") | |
| for cid, name in sorted(cats.items()): | |
| lines.append( | |
| f" {cid:>3} {name!r:30} anns={ann_count[cid]:>4} imgs={img_presence[cid]:>3} max/img={max_per_img[cid]}" | |
| ) | |
| lines.append("-- tracks") | |
| for t in tracks: | |
| c = csv_by_tid.get(t["track_id"]) | |
| lines.append( | |
| f" {t['track_id']:24} cat={t['category']!r:24} csv_cat={(c or {}).get('category')!r}" | |
| ) | |
| lines.append(f" en: {t.get('description_en')}") | |
| lines.append(f" zh: {t.get('description_zh')}") | |
| if t.get("temporal_profile"): | |
| lines.append(f" tp: {t['temporal_profile']}") | |
| if t.get("motion") or t.get("is_static") is not None: | |
| lines.append(f" motion={t.get('motion')} static={t.get('is_static')}") | |
| lines.append("-- queries") | |
| for q in qs: | |
| lines.append( | |
| f" {q['query_id']:22} [{q.get('query_type')}] ids={q.get('target_track_ids')} " | |
| f"anchor={q.get('expected_temporal_anchor')} rel={q.get('temporal_relation')}" | |
| ) | |
| lines.append(f" en: {q.get('text_en')}") | |
| lines.append(f" zh: {q.get('text_zh')}") | |
| (OUT / "trace_dump.txt").write_text("\n".join(lines), encoding="utf-8") | |
| print("\n".join(lines)) | |
| if __name__ == "__main__": | |
| main() | |