Eureka-Leo's picture
Add VWG-Bench dataset release
33fba32 verified
Raw
History Blame Contribute Delete
2.51 kB
from __future__ import annotations
import json
import shutil
from pathlib import Path
def load_records(path: str | Path) -> list[dict]:
value = json.loads(Path(path).read_text(encoding="utf-8"))
if not isinstance(value, list):
raise ValueError("External benchmark metadata must be a JSON array")
return value
def prepare_ruler(
metadata_json: str | Path,
videos_dir: str | Path,
output_dir: str | Path,
seeds: list[int],
filename_template: str,
) -> dict:
rows = load_records(metadata_json)
source_root = Path(videos_dir)
target_root = Path(output_dir)
copied = 0
missing = []
for row in rows:
source_id = Path(row["image_path"]).stem
for seed in seeds:
source = source_root / filename_template.format(
id=row["id"], id06=f"{row['id']:06d}", seed=seed
)
if not source.is_file():
missing.append(str(source))
continue
target = target_root / f"seed_{seed}" / row["task_name"] / f"{source_id}.mp4"
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, target)
copied += 1
return {"copied": copied, "missing": len(missing), "missing_examples": missing[:10]}
def prepare_vreason(
metadata_json: str | Path,
videos_dir: str | Path,
output_dir: str | Path,
seeds: list[int],
model_name: str,
filename_template: str,
) -> dict:
rows = load_records(metadata_json)
source_root = Path(videos_dir)
target_root = Path(output_dir)
copied = 0
missing = []
for row in rows:
original_stem = Path(row["image_path"]).stem
task = row["task_name"]
prefix = f"{task}_"
ground_truth_id = (
original_stem[len(prefix) :] if original_stem.startswith(prefix) else original_stem
)
for seed in seeds:
source = source_root / filename_template.format(
id=row["id"], id06=f"{row['id']:06d}", seed=seed
)
if not source.is_file():
missing.append(str(source))
continue
target = (
target_root
/ f"{task}_{model_name}_{ground_truth_id}_{seed}.mp4"
)
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, target)
copied += 1
return {"copied": copied, "missing": len(missing), "missing_examples": missing[:10]}