File size: 3,495 Bytes
aa7e82c | 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | """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()
|