Add dataset loading script for proper image display
Browse files- dataset_info.py +75 -0
dataset_info.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dataset loading script for HuggingFace
|
| 2 |
+
import datasets
|
| 3 |
+
import os
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
_DESCRIPTION = """
|
| 7 |
+
CameraBench Binary Evaluation Dataset with video frames and optical flow visualizations.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
class CameraBenchConfig(datasets.BuilderConfig):
|
| 11 |
+
"""BuilderConfig for CameraBench."""
|
| 12 |
+
def __init__(self, **kwargs):
|
| 13 |
+
super(CameraBenchConfig, self).__init__(**kwargs)
|
| 14 |
+
|
| 15 |
+
class CameraBench(datasets.GeneratorBasedBuilder):
|
| 16 |
+
"""CameraBench dataset with frames and optical flows."""
|
| 17 |
+
|
| 18 |
+
VERSION = datasets.Version("1.0.0")
|
| 19 |
+
|
| 20 |
+
def _info(self):
|
| 21 |
+
return datasets.DatasetInfo(
|
| 22 |
+
description=_DESCRIPTION,
|
| 23 |
+
features=datasets.Features({
|
| 24 |
+
"video_name": datasets.Value("string"),
|
| 25 |
+
"video_path": datasets.Value("string"),
|
| 26 |
+
"frames_path": datasets.Value("string"),
|
| 27 |
+
"optical_flows_path": datasets.Value("string"),
|
| 28 |
+
"frames": datasets.Sequence(datasets.Image()), # All frames as sequence
|
| 29 |
+
"optical_flows": datasets.Sequence(datasets.Image()), # All flows as sequence
|
| 30 |
+
"num_frames": datasets.Value("int32"),
|
| 31 |
+
"num_flows": datasets.Value("int32"),
|
| 32 |
+
"question": datasets.Value("string"),
|
| 33 |
+
"label": datasets.Value("string"),
|
| 34 |
+
"task": datasets.Value("string"),
|
| 35 |
+
"label_name": datasets.Value("string"),
|
| 36 |
+
})
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def _split_generators(self, dl_manager):
|
| 40 |
+
return [
|
| 41 |
+
datasets.SplitGenerator(
|
| 42 |
+
name=datasets.Split.TRAIN,
|
| 43 |
+
gen_kwargs={"metadata_path": "data.jsonl"},
|
| 44 |
+
),
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
def _generate_examples(self, metadata_path):
|
| 48 |
+
import json
|
| 49 |
+
idx = 0
|
| 50 |
+
with open(metadata_path, "r") as f:
|
| 51 |
+
for line in f:
|
| 52 |
+
record = json.loads(line)
|
| 53 |
+
|
| 54 |
+
# Get paths to all frames and flows
|
| 55 |
+
video_base_name = record['video_name'].replace('.mp4', '')
|
| 56 |
+
frames_dir = f"frames/{video_base_name}"
|
| 57 |
+
flows_dir = f"optical_flows/{video_base_name}"
|
| 58 |
+
|
| 59 |
+
# Collect all frame paths
|
| 60 |
+
frame_paths = []
|
| 61 |
+
if os.path.exists(frames_dir):
|
| 62 |
+
frame_files = sorted([f for f in os.listdir(frames_dir) if f.endswith('.png')])
|
| 63 |
+
frame_paths = [os.path.join(frames_dir, f) for f in frame_files]
|
| 64 |
+
|
| 65 |
+
# Collect all flow paths
|
| 66 |
+
flow_paths = []
|
| 67 |
+
if os.path.exists(flows_dir):
|
| 68 |
+
flow_files = sorted([f for f in os.listdir(flows_dir) if f.endswith('.png')])
|
| 69 |
+
flow_paths = [os.path.join(flows_dir, f) for f in flow_files]
|
| 70 |
+
|
| 71 |
+
record['frames'] = frame_paths
|
| 72 |
+
record['optical_flows'] = flow_paths
|
| 73 |
+
|
| 74 |
+
yield idx, record
|
| 75 |
+
idx += 1
|