Datasets:
Download scripts/extract_dataset.py from dcowg/wildshadow-video: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/datasets/dcowg/wildshadow-video/resolve/main/scripts/extract_dataset.py
- Command line
-
hf download hf://datasets/dcowg/wildshadow-video/scripts/extract_dataset.py
-
curl -L -o extract_dataset.py https://huggingface.co/datasets/dcowg/wildshadow-video/resolve/main/scripts/extract_dataset.py
2.07 kB
| #!/usr/bin/env python3 | |
| """Extract all or part of WildShadow-Video into paired frame directories.""" | |
| from __future__ import annotations | |
| import argparse | |
| import csv | |
| import subprocess | |
| from concurrent.futures import ThreadPoolExecutor, as_completed | |
| from pathlib import Path | |
| def extract(video: Path, destination: Path) -> None: | |
| destination.mkdir(parents=True, exist_ok=True) | |
| subprocess.run([ | |
| "ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-i", str(video), | |
| "-vsync", "0", "-start_number", "0", str(destination / "rgb_%06d.png"), | |
| ], check=True) | |
| def extract_row(root: Path, output: Path, row: dict[str, str]) -> None: | |
| destination = output / row["split"] / row["dataset"] / row["clip_id"] | |
| extract(root / row["shadow_video"], destination / "origin") | |
| extract(root / row["shadow_free_video"], destination / "shadow_free") | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1]) | |
| parser.add_argument("--output", required=True, type=Path) | |
| parser.add_argument("--split", choices=("train", "test")) | |
| parser.add_argument("--dataset", choices=("3dfront", "icity", "infinigen", "hssd")) | |
| parser.add_argument("--workers", type=int, default=8) | |
| args = parser.parse_args() | |
| with (args.root / "manifests" / "clips.csv").open(newline="", encoding="utf-8") as handle: | |
| rows = list(csv.DictReader(handle)) | |
| if args.split: | |
| rows = [row for row in rows if row["split"] == args.split] | |
| if args.dataset: | |
| rows = [row for row in rows if row["dataset"] == args.dataset] | |
| with ThreadPoolExecutor(max_workers=args.workers) as pool: | |
| futures = [pool.submit(extract_row, args.root, args.output, row) for row in rows] | |
| for index, future in enumerate(as_completed(futures), 1): | |
| future.result() | |
| if index % 50 == 0 or index == len(futures): | |
| print(f"Extracted {index}/{len(futures)} clips", flush=True) | |
| if __name__ == "__main__": | |
| main() | |