| |
| """Audit the published dataset: is every capture actually complete on HF? |
| |
| Checks, per capture, that the repo really holds what a user needs: |
| videos/cam00.mp4 .. cam31.mp4 (32, all LFS) |
| smplx.npz, cameras.json, capture.json, preview.jpg |
| and cross-checks the frame count against the capture card, so a capture that uploaded |
| "successfully" but landed short is reported as SHORT rather than passing silently. |
| |
| Exit code is non-zero if any expected capture is incomplete, so it can gate a release. |
| |
| python audit_repo.py |
| python audit_repo.py --json |
| """ |
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import sys |
| from collections import defaultdict |
|
|
| from huggingface_hub import HfApi, hf_hub_download |
|
|
| REPO = "initialneil/DREAMS-AVATAR" |
| EXPECTED = ["P1C1", "P1C2", "P2C1", "P2C2", "P3C1", "P3C2", |
| "P4C1", "P4C2", "P5C2", "P6C2"] |
| SMALL = ["smplx.npz", "cameras.json", "capture.json", "preview.jpg"] |
| N_CAMS = 32 |
|
|
|
|
| def audit(repo: str = REPO, expected: list[str] = None) -> tuple[list[dict], bool]: |
| expected = expected or EXPECTED |
| api = HfApi() |
| tree = [x for x in api.list_repo_tree(repo, repo_type="dataset", recursive=True, |
| expand=True) if hasattr(x, "size")] |
| per = defaultdict(lambda: {"mp4": set(), "small": set(), "bytes": 0, "lfs_ok": True}) |
| for f in tree: |
| p = f.path.split("/") |
| if p[0] != "data" or len(p) < 3: |
| continue |
| c = p[1] |
| per[c]["bytes"] += f.size |
| if len(p) == 4 and p[2] == "videos" and p[3].endswith(".mp4"): |
| per[c]["mp4"].add(p[3]) |
| if not f.lfs: |
| per[c]["lfs_ok"] = False |
| elif len(p) == 3: |
| per[c]["small"].add(p[2]) |
|
|
| rows, ok_all = [], True |
| for c in expected: |
| d = per.get(c) |
| if not d: |
| rows.append({"capture": c, "status": "ABSENT", "mp4": 0, |
| "missing": SMALL, "gib": 0.0, "n_frames": None}) |
| ok_all = False |
| continue |
| missing_mp4 = [f"cam{i:02d}.mp4" for i in range(N_CAMS) |
| if f"cam{i:02d}.mp4" not in d["mp4"]] |
| missing_small = [s for s in SMALL if s not in d["small"]] |
| n_frames = None |
| try: |
| card = json.load(open(hf_hub_download(repo, f"data/{c}/capture.json", |
| repo_type="dataset"))) |
| n_frames = card.get("n_frames") |
| except Exception: |
| pass |
| ok = not missing_mp4 and not missing_small and d["lfs_ok"] |
| ok_all &= ok |
| rows.append({ |
| "capture": c, |
| "status": "OK" if ok else "SHORT", |
| "mp4": len(d["mp4"]), |
| "missing": missing_mp4[:4] + missing_small, |
| "lfs_ok": d["lfs_ok"], |
| "gib": round(d["bytes"] / 2**30, 3), |
| "n_frames": n_frames, |
| }) |
| return rows, ok_all |
|
|
|
|
| def main() -> int: |
| ap = argparse.ArgumentParser(description=__doc__, |
| formatter_class=argparse.RawDescriptionHelpFormatter) |
| ap.add_argument("--repo", default=REPO) |
| ap.add_argument("--json", action="store_true") |
| a = ap.parse_args() |
| rows, ok = audit(a.repo) |
| if a.json: |
| print(json.dumps(rows, indent=2)) |
| else: |
| print(f"{'capture':8} {'status':7} {'mp4':>6} {'frames':>7} {'size':>9} missing") |
| for r in rows: |
| print(f"{r['capture']:8} {r['status']:7} {r['mp4']:>3}/32 " |
| f"{str(r['n_frames'] or '?'):>7} {r['gib']:>7.3f}G " |
| f"{','.join(r['missing']) if r['missing'] else '-'}") |
| tot = sum(r["gib"] for r in rows) |
| print(f"\n{len([r for r in rows if r['status']=='OK'])}/{len(rows)} captures complete" |
| f", {tot:.2f} GiB") |
| return 0 if ok else 1 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|