Buckets:
| #!/usr/bin/env python3 | |
| """Populate the re-warp cache from camera task dirs that were built before the cache existed. | |
| Pure optimization. ``build_v1.rewarped_clip`` regenerates anything the cache is missing, so | |
| deleting ``sources/rewarped/`` and rebuilding gives the same dataset — this just skips ~80 warps | |
| that have already been computed. | |
| **Only two-condition camera tasks are safe to seed from.** Each task truncates its own files to | |
| the common length of its own conditions (``harmonize_frames``), so a four-condition task's pose | |
| video may be shorter than the warp actually produced. In a ``camera`` + *one other* task the other | |
| condition is never the one that gets cut — the warp already truncated it to | |
| ``min(camera, condition)``, so it is the shortest and the camera clip is what shrinks. That makes | |
| its files exactly the full-length warp the cache wants. | |
| Usage | |
| ===== | |
| python seed_rewarp_cache.py [--dry-run] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import shutil | |
| from pathlib import Path | |
| from build_v1 import SOURCES, V1 | |
| # task dir -> {condition file in the task -> name in the cache} | |
| SEED_FROM = { | |
| "camera_pose": {"pose/{sid}.mp4": "pose.mp4", "pose/raw/{sid}.npy": "pose.npy"}, | |
| "camera_depth": {"depth/{sid}.mp4": "depth.mp4"}, | |
| "camera_inpainting": {"inpainting/{sid}.mp4": "inpainting.mp4", | |
| "inpainting/bbox/{sid}.mp4": "inpainting_bbox.mp4"}, | |
| } | |
| CONDITION_OF = {"pose.mp4": "pose", "depth.mp4": "depth", "inpainting.mp4": "inpainting"} | |
| def main() -> None: | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("--dry-run", action="store_true") | |
| args = ap.parse_args() | |
| copied = skipped = 0 | |
| for task, files in SEED_FROM.items(): | |
| task_dir = V1 / "pairwise" / task | |
| pairing_path = task_dir / "pairing.json" | |
| if not pairing_path.exists(): | |
| print(f" {task}: not built, nothing to seed from") | |
| continue | |
| pairing = json.loads(pairing_path.read_text()) | |
| for sid, entry in pairing["samples"].items(): | |
| cache = SOURCES / "rewarped" / sid | |
| meta_path = cache / "meta.json" | |
| meta = json.loads(meta_path.read_text()) if meta_path.exists() else {} | |
| for template, cached_name in files.items(): | |
| src = task_dir / template.format(sid=sid) | |
| dst = cache / cached_name | |
| if not src.exists(): | |
| continue | |
| if dst.exists(): | |
| skipped += 1 | |
| continue | |
| if args.dry_run: | |
| print(f" would copy {src.relative_to(V1)} -> {dst.relative_to(V1)}") | |
| else: | |
| cache.mkdir(parents=True, exist_ok=True) | |
| shutil.copy2(src, dst) | |
| copied += 1 | |
| for cached_name, condition in CONDITION_OF.items(): | |
| if (cache / cached_name).exists() or args.dry_run: | |
| info = entry.get("warp", {}).get(condition) | |
| if info: | |
| meta[condition] = info | |
| meta.setdefault("strength", entry.get("rewarp_strength")) | |
| meta.setdefault("camera_coverage_mean", entry.get("camera_coverage_mean")) | |
| if not args.dry_run and meta: | |
| cache.mkdir(parents=True, exist_ok=True) | |
| meta_path.write_text(json.dumps(meta, indent=2) + "\n") | |
| print(f"\n{copied} file(s) seeded, {skipped} already cached -> {SOURCES / 'rewarped'}") | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 3.63 kB
- Xet hash:
- 5416618949193160be9e75bbcc5c3827709a4ca796e31b6035939053599af561
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.