Datasets:
Download code/tools/verify.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 3.67 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/tools/verify.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/tools/verify.py
-
curl -L -o verify.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/tools/verify.py
3.67 kB
| #!/usr/bin/env python3 | |
| """Check the staged tree: every item row equals the evaluated pack row except for paths; every path resolves inside | |
| the merged repo (DISK root ∪ SHM root) to the same file (inode) the pack used; truth rows unchanged; scoring self-check.""" | |
| import csv, json, os, sys, collections as C | |
| from pathlib import Path | |
| RUNS = Path('${LOCAL}/simulation-workspace/runs') | |
| DISK = RUNS / 'hf-release-20261120/stage'; SHM = Path('${LOCAL}/shm/ent400/hf-release-20261120/stage') | |
| G = ['g1', 'g2', 'g3', 'g4', 'g5'] | |
| def jl(p): return [json.loads(l) for l in open(p, encoding='utf-8') if l.strip()] | |
| def where(rel): | |
| for r in (DISK, SHM): | |
| if (r / rel).is_file(): return r / rel | |
| return None | |
| def strip(r): | |
| r = json.loads(json.dumps(r)) | |
| for v in r['videos']: | |
| v.pop('path'); (v.get('clip') or {}).pop('source', None) | |
| for im in r.get('images') or []: im.pop('path') | |
| return r | |
| def ino(p): s = os.stat(p); return (s.st_dev, s.st_ino) | |
| def res(p, base): return Path(p) if str(p).startswith('/') else Path(base) / p | |
| PARTS = { | |
| 'v0.2/core3600': [(RUNS / f'eval-v02-{pk}-{g}') for g in G for pk in ('fixA', 'fixB', 'k3supp', 'redraw')], | |
| 'v0.2/altform/b1-720': [RUNS / 'eval-v02-altform720-k3', RUNS / 'eval-v02-altform-supp1'], | |
| 'v0.2/altform/b2-1440': [RUNS / 'eval-v02-altform1440'], 'v0.2/altform/b3-rest978': [RUNS / 'eval-v02-altform978'], | |
| 'ent400/half1/core3600': [RUNS / f'eval-ent400-k3-half1-{g}' for g in G], | |
| 'ent400/half2-reserve/core3600': [RUNS / f'eval-ent400-k3-half2-{g}' for g in G], | |
| 'ent400/half1/altform/b1-720': [RUNS / 'eval-ent400-altform720-half1'], 'ent400/half1/altform/b2-1440': [RUNS / 'eval-ent400-altform1440-half1'], | |
| 'ent400/half1/altform/b3-rest990': [RUNS / 'eval-ent400-altform990-half1'], | |
| } | |
| bad = C.Counter(); n = C.Counter() | |
| for part, packs in PARTS.items(): | |
| src = {} | |
| for pk in packs: # later packs override (merge rule order) | |
| for v, f in (('items', 'items/items.jsonl'), ('gemini', 'gemini-items/items.jsonl'), ('truth', 'items/truth.jsonl')): | |
| for r in jl(pk / f): src[(v, r['item_id'])] = (r, pk / ('gemini-items' if v == 'gemini' else 'items')) | |
| for v, fn in (('items', 'items.jsonl'), ('gemini', 'gemini-items.jsonl'), ('truth', 'truth.jsonl')): | |
| rows = jl(DISK / part / fn); n[part] = len(rows) | |
| for r in rows: | |
| o, odir = src[(v, r['item_id'])] | |
| if v == 'truth': | |
| bad['truth'] += r != o; continue | |
| if strip(r) != strip(o): bad[f'{part}:{v}:content'] += 1 | |
| for a, b in zip(r['videos'], o['videos']): | |
| p = where(os.path.normpath(Path(part) / a['path'])) | |
| if p is None or ino(p) != ino(os.path.realpath(res(b['path'], odir))): bad[f'{part}:{v}:video'] += 1 | |
| if a.get('clip'): | |
| q = where(os.path.normpath(Path(part) / a['clip']['source'])) | |
| if q is None or ino(q) != ino(os.path.realpath(b['clip']['source'])): bad[f'{part}:{v}:clipsrc'] += 1 | |
| for a, b in zip(r.get('images') or [], o.get('images') or []): | |
| p = where(os.path.normpath(Path(part) / a['path'])) | |
| if p is None or open(p, 'rb').read() != open(res(b['path'], odir), 'rb').read(): bad[f'{part}:{v}:image'] += 1 | |
| # alt_ids alignment | |
| if 'altform' in part: | |
| alt = [r['alt_item_id'] for r in csv.DictReader(open(where(Path(part) / 'alt_ids.tsv')), delimiter='\t')] | |
| bad[f'{part}:alt_order'] += alt != [r['item_id'] for r in jl(DISK / part / 'items.jsonl')] | |
| print('items per part:', dict(n)); print('problems:', {k: v for k, v in bad.items() if v} or 0) | |
| sys.exit(1 if any(bad.values()) else 0) | |