Download scripts/check_layout.py from Jinxin-Ai/GraftRay: direct link, hf CLI and curl.
- Browser
- Download file 4.45 kB
-
https://huggingface.co/datasets/Jinxin-Ai/GraftRay/resolve/main/scripts/check_layout.py
- Command line
-
hf download hf://datasets/Jinxin-Ai/GraftRay/scripts/check_layout.py
-
curl -L -o check_layout.py https://huggingface.co/datasets/Jinxin-Ai/GraftRay/resolve/main/scripts/check_layout.py
4.45 kB
| #!/usr/bin/env python | |
| """Check a download of this dataset: every file a scene config refers to exists, per-Gaussian tensors have one row per | |
| Gaussian of the .ply, object files exist, and (with --hash) every file matches MANIFEST.tsv. | |
| python scripts/check_layout.py [--hash] [--scenes NAME ...] | |
| A scene (or object) that is not part of your download is reported as "absent", not as an error; a scene that is | |
| present but incomplete is an error. torch is optional (tensor shapes are skipped without it).""" | |
| import argparse, hashlib, json, sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def ply_count(p): | |
| with open(p, 'rb') as f: | |
| for line in f: | |
| if line.startswith(b'element vertex'): | |
| return int(line.split()[-1]) | |
| if line.startswith(b'end_header'): | |
| break | |
| raise ValueError(f'no vertex count in {p}') | |
| def main(): | |
| ap = argparse.ArgumentParser(); ap.add_argument('--hash', action='store_true'); ap.add_argument('--scenes', nargs='*') | |
| a = ap.parse_args() | |
| try: | |
| import torch | |
| except ImportError: | |
| torch = None | |
| print('torch not available: tensor shapes not checked') | |
| err = 0 | |
| names = a.scenes or sorted(p.name for p in (ROOT / 'scenes').iterdir() if p.is_dir()) | |
| for name in names: | |
| sj = ROOT / 'scenes' / name / 'scene.json' | |
| if not sj.exists(): | |
| print(f'{name}: absent'); continue | |
| sc = json.load(open(sj)); msg = [] | |
| if not (ROOT / sc['ply']).exists(): | |
| print(f'{name}: absent (no point_cloud.ply; held back or not downloaded)'); continue | |
| n = ply_count(ROOT / sc['ply']) | |
| cj = json.load(open(ROOT / sc['dataset'] / 'cameras.json')) | |
| assert {'w', 'h', 'fx', 'fy', 'cx', 'cy'} <= set(cj['intrinsics']) | |
| vj = json.load(open(ROOT / sc['views'])); assert len(vj['eyes']) == len(vj['looks']) | |
| for vn, v in sc['variants'].items(): | |
| for k in ('albedo.pt', 'roughness.pt', 'metallic.pt'): | |
| p = ROOT / v['materials'] / k | |
| if not p.exists(): | |
| msg.append(f'missing {p.relative_to(ROOT)}'); continue | |
| if torch is not None and torch.load(p, map_location='cpu', weights_only=True).shape[0] != n: | |
| msg.append(f'{p.relative_to(ROOT)}: rows != {n}') | |
| for k in ('normals', 'emitter', 'light'): | |
| p = ROOT / v[k] | |
| if not p.exists(): | |
| msg.append(f'missing {v[k]}') | |
| elif k != 'light' and torch is not None and torch.load(p, map_location='cpu', weights_only=True).shape[0] != n: | |
| msg.append(f'{v[k]}: rows != {n}') | |
| if (ROOT / v['light']).exists(): | |
| lw = json.load(open(ROOT / v['light']))['windows'] | |
| assert all({'center', 'u', 'v', 'half_size'} <= set(w) for w in lw) | |
| objs = json.load(open(ROOT / sc['objects'])) | |
| miss = [o['glb'] for o in objs if not (ROOT / o['glb']).exists()] | |
| cfg = [ROOT / 'configs' / f'{name}_{vn}.json' for vn in sc['variants']] | |
| msg += [f'missing {c.relative_to(ROOT)}' for c in cfg if not c.exists()] | |
| state = 'OK' if not msg else 'ERROR' | |
| err += bool(msg) | |
| print(f'{name}: {state} {n:,} Gaussians, {len(vj["eyes"])} views, {len(objs)} objects' | |
| + (f', {len(miss)} object file(s) absent: {", ".join(miss)}' if miss else '') | |
| + (', gt' if (ROOT / 'scenes' / name / 'gt' / 'config.json').exists() else '') | |
| + (', reference' if (ROOT / 'scenes' / name / 'reference').exists() else '') | |
| + ''.join(f'\n {m}' for m in msg)) | |
| if a.hash: | |
| bad = n_ok = n_abs = 0 | |
| for line in open(ROOT / 'MANIFEST.tsv').read().splitlines()[1:]: | |
| path, size, digest = line.split('\t')[:3] | |
| p = ROOT / path | |
| if not p.exists(): | |
| n_abs += 1; continue | |
| h = hashlib.sha256() | |
| with open(p, 'rb') as f: | |
| for c in iter(lambda: f.read(1 << 22), b''): | |
| h.update(c) | |
| if h.hexdigest() != digest or p.stat().st_size != int(size): | |
| bad += 1; print('HASH MISMATCH', path) | |
| else: | |
| n_ok += 1 | |
| print(f'manifest: {n_ok} ok, {bad} mismatching, {n_abs} absent'); err += bad | |
| sys.exit(1 if err else 0) | |
| if __name__ == '__main__': | |
| main() | |