File size: 1,545 Bytes
326d3cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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))