Download scripts/validate.py from mosaichunk/RememBench: direct link, hf CLI and curl.
- Browser
- Download file 5.09 kB
-
https://huggingface.co/datasets/mosaichunk/RememBench/resolve/main/scripts/validate.py
- Command line
-
hf download hf://datasets/mosaichunk/RememBench/scripts/validate.py
-
curl -L -o validate.py https://huggingface.co/datasets/mosaichunk/RememBench/resolve/main/scripts/validate.py
5.09 kB
| #!/usr/bin/env python3 | |
| """Check release integrity, cohorts, camera arrays, and reference statistics.""" | |
| import argparse | |
| from collections import Counter | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| def check(condition, message): | |
| if not condition: | |
| raise ValueError(message) | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__) | |
| ap.add_argument('--root', type=Path, default=Path(__file__).resolve().parents[1]) | |
| ap.add_argument('--require-images', action='store_true') | |
| args = ap.parse_args() | |
| root = args.root | |
| for line in (root / 'checksums.sha256').read_text().splitlines(): | |
| expected, relative = line.split(' ', 1) | |
| path = root / relative | |
| check(path.is_file(), f'Missing release file: {relative}') | |
| check(hashlib.sha256(path.read_bytes()).hexdigest() == expected, f'Checksum mismatch: {relative}') | |
| def rows(name): | |
| return [json.loads(s) for s in (root / name).read_text().splitlines()] | |
| t2v, i2v = rows('data/t2v/test.jsonl'), rows('data/i2v/test.jsonl') | |
| sources = rows('sources/i2v_images.jsonl') | |
| check(len(t2v) == len({r['scene_id'] for r in t2v}) == 100, 'T2V scene count or uniqueness mismatch') | |
| check(len(i2v) == len({r['sample_id'] for r in i2v}) == 750, 'I2V sample count or uniqueness mismatch') | |
| check(len(sources) == len({r['scene_id'] for r in i2v}) == 150, 'I2V scene count mismatch') | |
| check(Counter(r['scene_type'] for r in sources) == {'indoor': 50, 'outdoor': 100}, 'Incorrect scene mix') | |
| for row in t2v + i2v: | |
| check(isinstance(row['seed'], str) and row['seed'].isdigit(), 'Seed must be a decimal string') | |
| check(0 <= int(row['seed']) < 2**63, 'Seed out of range') | |
| for row in t2v: | |
| check(len(row['prompts']) == 4 and all(row['prompts']), 'Incomplete T2V prompt schedule') | |
| check(row['prompt_start_seconds'] == [0.0, 3.6, 6.2, 11.2], 'T2V prompt timing mismatch') | |
| cohorts = {} | |
| for row in i2v: | |
| cohorts.setdefault(row['setting'], set()).add(row['scene_id']) | |
| with np.load(root / row['trajectory_path'], allow_pickle=False) as data: | |
| p, k = data['poses'], data['intrinsics'] | |
| check(p.shape == (row['pose_samples'], 4, 4), 'Pose shape mismatch') | |
| check(k.shape == (row['intrinsics_samples'], 4), 'Intrinsics shape mismatch') | |
| check(np.isfinite(p).all() and np.isfinite(k).all(), 'Non-finite camera values') | |
| check(np.allclose(k, k[0]), 'Expected constant camera intrinsics') | |
| check(np.allclose(p[0], p[-1], atol=1e-5), 'Trajectory does not return to its origin') | |
| check(np.allclose(p[:, 3], [0, 0, 0, 1]), 'Invalid homogeneous pose') | |
| r = p[:, :3, :3] | |
| check(np.allclose(r.transpose(0, 2, 1) @ r, np.eye(3), atol=1e-5), 'Invalid rotation matrix') | |
| check(np.allclose(np.linalg.det(r), 1, atol=1e-5), 'Invalid rotation determinant') | |
| moving = np.max(np.linalg.norm(p[:, :3, 3] - p[0, :3, 3], axis=1)) > 1e-5 | |
| check(bool(moving) == row['translation'], 'Translation flag disagrees with camera path') | |
| all_scenes = {r['scene_id'] for r in sources} | |
| outdoors = {r['scene_id'] for r in sources if r['scene_type'] == 'outdoor'} | |
| for angle in [90, 180, 360]: | |
| check(cohorts[f'rotation_{angle}'] == all_scenes, 'Rotation cohort mismatch') | |
| check(cohorts[f'translation_{angle}'] == outdoors, 'Translation cohort mismatch') | |
| pairs = rows('evaluation/t2v_reference_pairs.jsonl') | |
| check(len(pairs) == 600, 'Missing reference annotations') | |
| check(len({(p['scene_id'], p['method'], p['comparison_budget_chunks']) for p in pairs}) == 600, | |
| 'Duplicate reference annotations') | |
| for p in pairs: | |
| check(0 <= p['departure_frame'] < p['revisit_frame'] < 379, 'Reference frame out of range') | |
| summary = json.loads((root / 'evaluation/t2v_reference_summary.json').read_text()) | |
| for s in summary: | |
| subset = [p for p in pairs if p['method'] == s['method'] and p['comparison_budget_chunks'] == s['comparison_budget_chunks']] | |
| check(len(subset) == s['n'] == 100, 'Reference cohort mismatch') | |
| for key in ['clip', 'lpips_alex']: | |
| check(np.isclose(np.median([p[key] for p in subset]), s[f'median_{key}']), 'Reference summary mismatch') | |
| prepared = 0 | |
| from PIL import Image | |
| for row in sources: | |
| path = root / row['image_path'] | |
| if args.require_images: | |
| check(path.is_file(), f'Missing conditioning image: {path}') | |
| if path.is_file(): | |
| image = Image.open(path).convert('RGB') | |
| check(image.size == (832, 480), 'Conditioning image dimensions differ') | |
| check(hashlib.sha256(image.tobytes()).hexdigest() == row['rgb_sha256'], 'Conditioning image differs') | |
| prepared += 1 | |
| print(json.dumps(dict(status='passed', t2v_samples=100, i2v_scenes=150, i2v_samples=750, | |
| trajectory_files=750, t2v_reference_pairs=600, prepared_images=prepared), indent=2)) | |
| if __name__ == '__main__': | |
| main() | |