Spaces:
Running on T4
Running on T4
Download tools/annotation/export_dataset.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/tools/annotation/export_dataset.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/tools/annotation/export_dataset.py
-
curl -L -o export_dataset.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/tools/annotation/export_dataset.py
1.55 kB
| """Export reviewed image labels; participant identity groups must not leak across splits.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| def grouped_split(records): | |
| groups = sorted({r["player_id"] for r in records}) | |
| if len(groups) < 3: | |
| raise ValueError("At least three distinct athletes are needed for train/validation/test separation") | |
| # Deterministic grouped split. Samples from an athlete never cross partitions. | |
| assignment = {g: ("test" if i == len(groups)-1 else "validation" if i == len(groups)-2 else "train") | |
| for i,g in enumerate(groups)} | |
| return [{**r, "split": assignment[r["player_id"]]} for r in records] | |
| if __name__ == "__main__": | |
| p = argparse.ArgumentParser() | |
| p.add_argument("index", help="JSON list of reviewed annotation files, player IDs and session IDs") | |
| p.add_argument("--output", required=True) | |
| args = p.parse_args() | |
| records = json.loads(Path(args.index).read_text()) | |
| for r in records: | |
| if not r.get("player_id") or not r.get("session_id"): | |
| raise ValueError("Dataset records require explicit athlete/session groups") | |
| labels = json.loads(Path(r["annotations_path"]).read_text()) | |
| if not labels.get("annotator") or not labels.get("input_sha256"): | |
| raise ValueError("Reviewed label provenance is missing") | |
| r["input_sha256"] = labels["input_sha256"] | |
| r["reviewed_frame_count"] = len(labels.get("frames", {})) | |
| Path(args.output).write_text(json.dumps(grouped_split(records), indent=2)) | |