File size: 4,448 Bytes
df3ef86 | 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | #!/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()
|