Download scripts/model/inference/split_panoramas.py from xiaohaoy/ViewingSoundPAQ: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/xiaohaoy/ViewingSoundPAQ/resolve/main/scripts/model/inference/split_panoramas.py
- Command line
-
hf download hf://xiaohaoy/ViewingSoundPAQ/scripts/model/inference/split_panoramas.py
-
curl -L -o split_panoramas.py https://huggingface.co/xiaohaoy/ViewingSoundPAQ/resolve/main/scripts/model/inference/split_panoramas.py
1.63 kB
| #!/usr/bin/env python3 | |
| """Split equirectangular street-view panoramas into 4 perspective views (yaw 0/90/180/270, 90-degree FOV, pitch 0), | |
| exactly as our training views were made (panorama_views.make_views: 512 x 512, vertical extent | |
| 360 * H / W degrees centred on the horizon, so vertically cropped panoramas such as Baidu 1024 x 384 work too). | |
| Views: <output>/<subfolder>/<stem>_yaw000.jpg ... _yaw270.jpg. Images with aspect < 1.8 are copied as one view. | |
| """ | |
| import sys as _sys | |
| from pathlib import Path as _Path | |
| _SCRIPTS = next(_p for _p in _Path(__file__).resolve().parents if _p.name == "scripts") | |
| _sys.path[:0] = [str(_SCRIPTS.parent), str(_SCRIPTS.parent / "models")] + [str(_d) for _d in sorted(_SCRIPTS.rglob("*")) if _d.is_dir() and _d.name != "__pycache__"] | |
| import argparse | |
| import sys | |
| from concurrent.futures import ThreadPoolExecutor | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent)) | |
| from panorama_views import make_views # noqa: E402 | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument("--input", type=Path, required=True) | |
| p.add_argument("--output", type=Path, required=True) | |
| p.add_argument("--size", type=int, default=512) | |
| p.add_argument("--workers", type=int, default=8) | |
| a = p.parse_args() | |
| exts = {".jpg", ".jpeg", ".png"} | |
| images = sorted(q for q in a.input.rglob("*") if q.suffix.lower() in exts) | |
| def one(q): | |
| return make_views(q, a.output / q.parent.relative_to(a.input), q.stem, a.size)[1] | |
| with ThreadPoolExecutor(a.workers) as pool: | |
| panos = sum(pool.map(one, images)) | |
| print(f"{len(images)} images ({panos} panoramas -> 4 views each) -> {a.output}") | |