File size: 3,179 Bytes
5b87325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Validate the local CRIA dataset layout and episode alignment."""
from __future__ import annotations

import argparse
import json
from pathlib import Path


def json_load(path: Path):
    with path.open(encoding="utf-8") as f:
        return json.load(f)


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--root", "--data-root", dest="root", type=Path,
        default=Path(__file__).resolve().parent.parent,
        help="Path to the CRIA dataset root",
    )
    args = parser.parse_args()
    root = args.root.expanduser().resolve()
    errors: list[str] = []
    task_dirs = sorted(p for group in root.iterdir() if group.is_dir() and not group.name.startswith(".")
                       for p in group.iterdir() if (p / "meta").is_dir())
    total = {"parquet": 0, "videos": 0, "episodes": 0, "stats": 0, "annotation": 0}
    if not task_dirs:
        errors.append(f"No task directories found below {root}")
    for task in task_dirs:
        meta = task / "meta"
        for name in ("info.json", "annotation.json", "episodes.jsonl", "episodes_stats.jsonl", "stats.json", "tasks.jsonl"):
            if not (meta / name).is_file(): errors.append(f"{task.relative_to(root)} missing meta/{name}")
        try:
            info = json_load(meta / "info.json")
            annotation = json_load(meta / "annotation.json")
            episodes = [json.loads(x) for x in (meta / "episodes.jsonl").read_text(encoding="utf-8").splitlines() if x.strip()]
            episode_stats = [x for x in (meta / "episodes_stats.jsonl").read_text(encoding="utf-8").splitlines() if x.strip()]
            json_load(meta / "stats.json")
        except Exception as exc:
            errors.append(f"{task.relative_to(root)} invalid metadata: {exc}")
            continue
        n = len(episodes)
        parquet = sorted((task / "data").rglob("episode_*.parquet"))
        videos = sorted((task / "videos").rglob("episode_*.mp4"))
        ann_n = len(annotation.get("episodes", {}))
        expected = info.get("total_episodes")
        if len(parquet) != n: errors.append(f"{task.relative_to(root)} parquet={len(parquet)} episodes={n}")
        if len(videos) != n * 3: errors.append(f"{task.relative_to(root)} videos={len(videos)} expected={n * 3}")
        if len(episode_stats) != n or ann_n != n: errors.append(f"{task.relative_to(root)} meta counts disagree")
        if expected != n: errors.append(f"{task.relative_to(root)} info.total_episodes={expected} episodes={n}")
        for key in total: total[key] += {"parquet": len(parquet), "videos": len(videos), "episodes": n, "stats": len(episode_stats), "annotation": ann_n}[key]
    backups = list(root.rglob("*.bak*"))
    if backups: errors.append(f"backup files found: {len(backups)}")
    print(f"Root: {root}")
    print(f"Tasks: {len(task_dirs)}")
    print("Totals: " + ", ".join(f"{k}={v}" for k, v in total.items()))
    if errors:
        print("FAILED")
        print("\n".join(f"- {e}" for e in errors))
        return 1
    print("PASSED: data, videos, and metadata are aligned.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())