Finalize simplified release interface for scripts/extract_vlac2_release_frames.py
Browse files
scripts/extract_vlac2_release_frames.py
CHANGED
|
@@ -20,11 +20,9 @@ from vlac2_release_common import (
|
|
| 20 |
discover_benchmark_jsons,
|
| 21 |
dump_json,
|
| 22 |
ensure_generated_marker,
|
| 23 |
-
ensure_release_tree,
|
| 24 |
infer_main_path_from_row,
|
| 25 |
load_json,
|
| 26 |
normalize_main_path,
|
| 27 |
-
resolve_benchmark_root,
|
| 28 |
)
|
| 29 |
|
| 30 |
try:
|
|
@@ -40,9 +38,7 @@ except ImportError:
|
|
| 40 |
|
| 41 |
@dataclass(frozen=True)
|
| 42 |
class EpisodeSpec:
|
| 43 |
-
group_key: str
|
| 44 |
main_path: Path
|
| 45 |
-
benchmark_sources: tuple[str, ...]
|
| 46 |
|
| 47 |
|
| 48 |
def parse_args() -> argparse.Namespace:
|
|
@@ -50,34 +46,10 @@ def parse_args() -> argparse.Namespace:
|
|
| 50 |
description="Extract the portable VLAC2 release benchmark episodes into the release-local JPG tree."
|
| 51 |
)
|
| 52 |
parser.add_argument(
|
| 53 |
-
"--
|
| 54 |
type=Path,
|
| 55 |
required=True,
|
| 56 |
-
help="
|
| 57 |
-
)
|
| 58 |
-
parser.add_argument(
|
| 59 |
-
"--raw-root",
|
| 60 |
-
type=Path,
|
| 61 |
-
default=None,
|
| 62 |
-
help="Override raw video root. Defaults to <release-root>/data.",
|
| 63 |
-
)
|
| 64 |
-
parser.add_argument(
|
| 65 |
-
"--output-root",
|
| 66 |
-
type=Path,
|
| 67 |
-
default=None,
|
| 68 |
-
help="Override extracted image root. Defaults to <release-root>/_extracted_frames.",
|
| 69 |
-
)
|
| 70 |
-
parser.add_argument(
|
| 71 |
-
"--benchmark-json",
|
| 72 |
-
action="append",
|
| 73 |
-
default=None,
|
| 74 |
-
help="Optional specific benchmark JSON(s). Defaults to discovering benchmark_splits/**/*.json inside the release root.",
|
| 75 |
-
)
|
| 76 |
-
parser.add_argument(
|
| 77 |
-
"--view-mode",
|
| 78 |
-
choices=["all-available", "main-only"],
|
| 79 |
-
default="all-available",
|
| 80 |
-
help="Extract only the benchmark main view, or all sibling observation.images.* views for the referenced episode.",
|
| 81 |
)
|
| 82 |
parser.add_argument("--jobs", type=int, default=max(1, (os.cpu_count() or 8) // 2))
|
| 83 |
parser.add_argument(
|
|
@@ -88,6 +60,10 @@ def parse_args() -> argparse.Namespace:
|
|
| 88 |
return parser.parse_args()
|
| 89 |
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
def require_decoder() -> None:
|
| 92 |
if cv2 is None and imageio is None:
|
| 93 |
raise SystemExit(
|
|
@@ -95,10 +71,7 @@ def require_decoder() -> None:
|
|
| 95 |
)
|
| 96 |
|
| 97 |
|
| 98 |
-
def
|
| 99 |
-
if raw_paths:
|
| 100 |
-
return [Path(path).resolve() for path in raw_paths]
|
| 101 |
-
benchmark_root = resolve_benchmark_root(release_root)
|
| 102 |
files = discover_benchmark_jsons(benchmark_root)
|
| 103 |
if not files:
|
| 104 |
raise SystemExit(f"No benchmark json found under {benchmark_root}")
|
|
@@ -139,8 +112,8 @@ def collect_episode_specs(benchmark_paths: list[Path]) -> tuple[list[EpisodeSpec
|
|
| 139 |
grouped[key][1].add(str(benchmark_path))
|
| 140 |
|
| 141 |
specs = [
|
| 142 |
-
EpisodeSpec(
|
| 143 |
-
for
|
| 144 |
]
|
| 145 |
stats["episodes_unique"] = len(specs)
|
| 146 |
return specs, stats
|
|
@@ -164,25 +137,11 @@ def resolve_main_video(raw_root: Path, main_path: Path) -> Path:
|
|
| 164 |
return preferred
|
| 165 |
|
| 166 |
|
| 167 |
-
def discover_view_videos(raw_root: Path, main_path: Path
|
| 168 |
main_video = resolve_main_video(raw_root, main_path)
|
| 169 |
if not main_video.exists():
|
| 170 |
raise FileNotFoundError(f"Missing raw video: {main_video}")
|
| 171 |
-
|
| 172 |
-
return [main_video]
|
| 173 |
-
|
| 174 |
-
chunk_dir = main_video.parent.parent
|
| 175 |
-
episode_file = main_video.name
|
| 176 |
-
discovered: list[Path] = []
|
| 177 |
-
for child in sorted(chunk_dir.iterdir()):
|
| 178 |
-
if not child.is_dir() or not child.name.startswith("observation.images."):
|
| 179 |
-
continue
|
| 180 |
-
candidate = child / episode_file
|
| 181 |
-
if candidate.exists():
|
| 182 |
-
discovered.append(candidate)
|
| 183 |
-
if main_video not in discovered:
|
| 184 |
-
discovered.insert(0, main_video)
|
| 185 |
-
return discovered
|
| 186 |
|
| 187 |
|
| 188 |
def manifest_path_for(output_dir: Path) -> Path:
|
|
@@ -319,19 +278,21 @@ def main() -> None:
|
|
| 319 |
args = parse_args()
|
| 320 |
require_decoder()
|
| 321 |
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
|
|
|
|
|
|
| 326 |
ensure_generated_marker(output_root)
|
| 327 |
-
benchmark_paths =
|
| 328 |
|
| 329 |
specs, stats = collect_episode_specs(benchmark_paths)
|
| 330 |
jobs: list[tuple[Path, Path]] = []
|
| 331 |
missing_raw_episodes: list[dict[str, str]] = []
|
| 332 |
for spec in specs:
|
| 333 |
try:
|
| 334 |
-
view_videos = discover_view_videos(
|
| 335 |
except FileNotFoundError as exc:
|
| 336 |
missing_raw_episodes.append(
|
| 337 |
{
|
|
@@ -341,7 +302,7 @@ def main() -> None:
|
|
| 341 |
)
|
| 342 |
continue
|
| 343 |
for video_path in view_videos:
|
| 344 |
-
jobs.append((video_path, output_dir_from_video(
|
| 345 |
|
| 346 |
results: list[dict[str, Any]] = []
|
| 347 |
with ThreadPoolExecutor(max_workers=max(1, args.jobs)) as executor:
|
|
@@ -366,9 +327,9 @@ def main() -> None:
|
|
| 366 |
summary = {
|
| 367 |
**stats,
|
| 368 |
"release_root": str(release_root),
|
| 369 |
-
"
|
|
|
|
| 370 |
"output_root": str(output_root),
|
| 371 |
-
"view_mode": args.view_mode,
|
| 372 |
"benchmark_files": [str(path) for path in benchmark_paths],
|
| 373 |
"jobs_total": len(jobs),
|
| 374 |
"jobs_extracted": sum(1 for row in results if row["status"] == "extracted"),
|
|
@@ -377,7 +338,7 @@ def main() -> None:
|
|
| 377 |
"missing_raw_episodes": missing_raw_episodes,
|
| 378 |
"results": results,
|
| 379 |
}
|
| 380 |
-
summary_path =
|
| 381 |
dump_json(summary_path, summary)
|
| 382 |
print(f"[frame-extraction] {summary_path}")
|
| 383 |
|
|
|
|
| 20 |
discover_benchmark_jsons,
|
| 21 |
dump_json,
|
| 22 |
ensure_generated_marker,
|
|
|
|
| 23 |
infer_main_path_from_row,
|
| 24 |
load_json,
|
| 25 |
normalize_main_path,
|
|
|
|
| 26 |
)
|
| 27 |
|
| 28 |
try:
|
|
|
|
| 38 |
|
| 39 |
@dataclass(frozen=True)
|
| 40 |
class EpisodeSpec:
|
|
|
|
| 41 |
main_path: Path
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
def parse_args() -> argparse.Namespace:
|
|
|
|
| 46 |
description="Extract the portable VLAC2 release benchmark episodes into the release-local JPG tree."
|
| 47 |
)
|
| 48 |
parser.add_argument(
|
| 49 |
+
"--data-root",
|
| 50 |
type=Path,
|
| 51 |
required=True,
|
| 52 |
+
help="Directory containing the extracted raw benchmark videos.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
)
|
| 54 |
parser.add_argument("--jobs", type=int, default=max(1, (os.cpu_count() or 8) // 2))
|
| 55 |
parser.add_argument(
|
|
|
|
| 60 |
return parser.parse_args()
|
| 61 |
|
| 62 |
|
| 63 |
+
def bundled_release_root() -> Path:
|
| 64 |
+
return SCRIPT_DIR.parent.resolve()
|
| 65 |
+
|
| 66 |
+
|
| 67 |
def require_decoder() -> None:
|
| 68 |
if cv2 is None and imageio is None:
|
| 69 |
raise SystemExit(
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
|
| 74 |
+
def benchmark_files_from_root(benchmark_root: Path) -> list[Path]:
|
|
|
|
|
|
|
|
|
|
| 75 |
files = discover_benchmark_jsons(benchmark_root)
|
| 76 |
if not files:
|
| 77 |
raise SystemExit(f"No benchmark json found under {benchmark_root}")
|
|
|
|
| 112 |
grouped[key][1].add(str(benchmark_path))
|
| 113 |
|
| 114 |
specs = [
|
| 115 |
+
EpisodeSpec(main_path=main_path)
|
| 116 |
+
for _group_key, (main_path, _sources) in sorted(grouped.items())
|
| 117 |
]
|
| 118 |
stats["episodes_unique"] = len(specs)
|
| 119 |
return specs, stats
|
|
|
|
| 137 |
return preferred
|
| 138 |
|
| 139 |
|
| 140 |
+
def discover_view_videos(raw_root: Path, main_path: Path) -> list[Path]:
|
| 141 |
main_video = resolve_main_video(raw_root, main_path)
|
| 142 |
if not main_video.exists():
|
| 143 |
raise FileNotFoundError(f"Missing raw video: {main_video}")
|
| 144 |
+
return [main_video]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
|
| 147 |
def manifest_path_for(output_dir: Path) -> Path:
|
|
|
|
| 278 |
args = parse_args()
|
| 279 |
require_decoder()
|
| 280 |
|
| 281 |
+
release_root = bundled_release_root()
|
| 282 |
+
benchmark_root = (release_root / "benchmark_splits").resolve()
|
| 283 |
+
if not benchmark_root.exists():
|
| 284 |
+
raise SystemExit(f"Missing benchmark_splits under {release_root}")
|
| 285 |
+
data_root = args.data_root.resolve()
|
| 286 |
+
output_root = (release_root / "_extracted_frames").resolve()
|
| 287 |
ensure_generated_marker(output_root)
|
| 288 |
+
benchmark_paths = benchmark_files_from_root(benchmark_root)
|
| 289 |
|
| 290 |
specs, stats = collect_episode_specs(benchmark_paths)
|
| 291 |
jobs: list[tuple[Path, Path]] = []
|
| 292 |
missing_raw_episodes: list[dict[str, str]] = []
|
| 293 |
for spec in specs:
|
| 294 |
try:
|
| 295 |
+
view_videos = discover_view_videos(data_root, spec.main_path)
|
| 296 |
except FileNotFoundError as exc:
|
| 297 |
missing_raw_episodes.append(
|
| 298 |
{
|
|
|
|
| 302 |
)
|
| 303 |
continue
|
| 304 |
for video_path in view_videos:
|
| 305 |
+
jobs.append((video_path, output_dir_from_video(data_root, output_root, video_path)))
|
| 306 |
|
| 307 |
results: list[dict[str, Any]] = []
|
| 308 |
with ThreadPoolExecutor(max_workers=max(1, args.jobs)) as executor:
|
|
|
|
| 327 |
summary = {
|
| 328 |
**stats,
|
| 329 |
"release_root": str(release_root),
|
| 330 |
+
"benchmark_root": str(benchmark_root),
|
| 331 |
+
"data_root": str(data_root),
|
| 332 |
"output_root": str(output_root),
|
|
|
|
| 333 |
"benchmark_files": [str(path) for path in benchmark_paths],
|
| 334 |
"jobs_total": len(jobs),
|
| 335 |
"jobs_extracted": sum(1 for row in results if row["status"] == "extracted"),
|
|
|
|
| 338 |
"missing_raw_episodes": missing_raw_episodes,
|
| 339 |
"results": results,
|
| 340 |
}
|
| 341 |
+
summary_path = output_root / "frame_extraction_summary.json"
|
| 342 |
dump_json(summary_path, summary)
|
| 343 |
print(f"[frame-extraction] {summary_path}")
|
| 344 |
|