Download scripts/check_dataset.py from Joringell/CRIA: direct link, hf CLI and curl.
- Browser
- Download file 3.18 kB
-
https://huggingface.co/datasets/Joringell/CRIA/resolve/main/scripts/check_dataset.py
- Command line
-
hf download hf://datasets/Joringell/CRIA/scripts/check_dataset.py
-
curl -L -o check_dataset.py https://huggingface.co/datasets/Joringell/CRIA/resolve/main/scripts/check_dataset.py
3.18 kB
| #!/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()) | |