Datasets:
Download tooling/eval/video_metadata.py from Irikos/RipBench: direct link, hf CLI and curl.
- Browser
- Download file 5.24 kB
-
https://huggingface.co/datasets/Irikos/RipBench/resolve/main/tooling/eval/video_metadata.py
- Command line
-
hf download hf://datasets/Irikos/RipBench/tooling/eval/video_metadata.py
-
curl -L -o video_metadata.py https://huggingface.co/datasets/Irikos/RipBench/resolve/main/tooling/eval/video_metadata.py
5.24 kB
| #!/usr/bin/env python3 | |
| """Per-video metadata for stratified / per-video evaluation (library + report). | |
| Joins the three per-video sources into one table keyed by video_id | |
| (RipBench-NNN / RipBench-NR-NNN) and exposes image_basename -> video_id: | |
| * NeurIPS_2026/video_metadata.csv class, split (s1.3), n_frames_sampled, | |
| source_provenance, license (filled by | |
| eval/dataset_accounting.py) | |
| * NeurIPS_2026/RipBench_video_annotation_data.csv viewpoint, primary visual signature, | |
| camera motion (expert-recorded) | |
| * Videos/RipBench_video_metadata.csv native width/height/fps/frame_count | |
| (ffprobe export of the source videos) | |
| Resolution buckets follow the posted stratified analysis: <720p / 720p / 1080p / >=1440p | |
| on the SHORT side of the native frame (portrait videos bucket by their width). | |
| Running the module prints the stratum sizes per split (sanity check). | |
| """ | |
| import csv | |
| import os | |
| import re | |
| REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| VIDEO_META_CSV = os.path.join(REPO_ROOT, "NeurIPS_2026", "video_metadata.csv") | |
| ANNOTATION_CSV = os.path.join(REPO_ROOT, "NeurIPS_2026", "RipBench_video_annotation_data.csv") | |
| TECH_CSV = os.path.join(REPO_ROOT, "NeurIPS_2026", "RipBench_video_technical_metadata.csv") | |
| VIEWPOINTS = ("aerial_bird's eye", "aerial_tilted", "elevated_beachfront", "water_level_beachfront") | |
| VIEWPOINT_LABEL = {"aerial_bird's eye": "Bird's eye", "aerial_tilted": "Aerial tilted", | |
| "elevated_beachfront": "Elevated", "water_level_beachfront": "Water-level"} | |
| SIGNATURES = ("dark_gap", "breaking_wave_gap", "sediment_plume", "foam_plume", | |
| "turbulent_band", "boundary_associated", "none") | |
| RES_BUCKETS = ("<720p", "720p", "1080p", ">=1440p") | |
| VIDEO_RE = re.compile(r"^(RipBench-(?:NR-)?\d+)_\d+\.\w+$") | |
| def video_id_of(image_name): | |
| """'RipBench-012_00345.jpg' -> 'RipBench-012' (basename or path accepted).""" | |
| m = VIDEO_RE.match(os.path.basename(image_name)) | |
| return m.group(1) if m else None | |
| def res_bucket(width, height): | |
| short = min(int(width), int(height)) | |
| if short < 720: | |
| return "<720p" | |
| if short < 1080: | |
| return "720p" | |
| if short < 1440: | |
| return "1080p" | |
| return ">=1440p" | |
| def load(): | |
| """{video_id: dict} with keys class, split, n_frames_sampled, source_provenance, | |
| license, viewpoint, signature, camera_motion, width, height, fps, frame_count, | |
| duration_s, res_bucket.""" | |
| meta = {} | |
| with open(VIDEO_META_CSV) as f: | |
| for r in csv.DictReader(f): | |
| meta[r["video_id"]] = { | |
| "class": r["class"], "split": r["split"], | |
| "n_frames_sampled": int(r["n_frames_sampled"]), | |
| "source_provenance": r.get("source_provenance", ""), | |
| "license": r.get("license", ""), "notes": r.get("notes", ""), | |
| } | |
| with open(ANNOTATION_CSV) as f: | |
| for r in csv.DictReader(f): | |
| v = r["Rip name"] | |
| if v not in meta: | |
| continue | |
| meta[v].update({ | |
| "viewpoint": r["Viewpoint"].strip(), | |
| "signature": r["Visual signature (primary)"].strip(), | |
| "camera_motion": r["Camera motion type"].strip(), | |
| "rip_present": r["Rip present"].strip() == "yes", | |
| }) | |
| with open(TECH_CSV) as f: | |
| for r in csv.DictReader(f): | |
| m = re.match(r"^(RipBench-(?:NR-)?\d{3})", r["file_name"]) # e.g. RipBench-021-003.mp4 | |
| v = m.group(1) if m else None | |
| if v not in meta: | |
| continue | |
| w, h = int(r["width"]), int(r["height"]) | |
| meta[v].update({"width": w, "height": h, "fps": float(r["fps"]), | |
| "frame_count": int(r["frame_count"]), | |
| "duration_s": float(r["duration_seconds"]), | |
| "res_bucket": res_bucket(w, h)}) | |
| missing = [v for v, d in meta.items() if "viewpoint" not in d or "width" not in d] | |
| assert not missing, f"metadata join incomplete for {missing[:5]}" | |
| return meta | |
| def videos_in(meta, split, rip_only=False): | |
| return sorted(v for v, d in meta.items() | |
| if d["split"] == split and (not rip_only or d["class"] == "rips")) | |
| def main(): | |
| meta = load() | |
| print(f"{len(meta)} videos") | |
| for split in ("train", "val", "test"): | |
| vids = videos_in(meta, split) | |
| print(f"\n[{split}] {len(vids)} videos " | |
| f"({sum(meta[v]['class'] == 'rips' for v in vids)} rip)") | |
| for key, order in (("viewpoint", VIEWPOINTS), ("signature", SIGNATURES), | |
| ("res_bucket", RES_BUCKETS)): | |
| counts = {k: [0, 0] for k in order} | |
| for v in vids: | |
| k = meta[v][key] | |
| counts.setdefault(k, [0, 0])[0 if meta[v]["class"] == "rips" else 1] += 1 | |
| print(f" {key:11s}: " + ", ".join(f"{k} {a}/{b}" for k, (a, b) in counts.items() | |
| if a + b)) | |
| if __name__ == "__main__": | |
| main() | |