|
|
|
|
|
import datasets |
|
|
import os |
|
|
from pathlib import Path |
|
|
|
|
|
_DESCRIPTION = """ |
|
|
CameraBench Binary Evaluation Dataset with video frames and optical flow visualizations. |
|
|
""" |
|
|
|
|
|
class CameraBenchConfig(datasets.BuilderConfig): |
|
|
"""BuilderConfig for CameraBench.""" |
|
|
def __init__(self, **kwargs): |
|
|
super(CameraBenchConfig, self).__init__(**kwargs) |
|
|
|
|
|
class CameraBench(datasets.GeneratorBasedBuilder): |
|
|
"""CameraBench dataset with frames and optical flows.""" |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
def _info(self): |
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=datasets.Features({ |
|
|
"video_name": datasets.Value("string"), |
|
|
"video_path": datasets.Value("string"), |
|
|
"frames_path": datasets.Value("string"), |
|
|
"optical_flows_path": datasets.Value("string"), |
|
|
"frames": datasets.Sequence(datasets.Image()), |
|
|
"optical_flows": datasets.Sequence(datasets.Image()), |
|
|
"num_frames": datasets.Value("int32"), |
|
|
"num_flows": datasets.Value("int32"), |
|
|
"question": datasets.Value("string"), |
|
|
"label": datasets.Value("string"), |
|
|
"task": datasets.Value("string"), |
|
|
"label_name": datasets.Value("string"), |
|
|
}) |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
gen_kwargs={"metadata_path": "data.jsonl"}, |
|
|
), |
|
|
] |
|
|
|
|
|
def _generate_examples(self, metadata_path): |
|
|
import json |
|
|
idx = 0 |
|
|
with open(metadata_path, "r") as f: |
|
|
for line in f: |
|
|
record = json.loads(line) |
|
|
|
|
|
|
|
|
video_base_name = record['video_name'].replace('.mp4', '') |
|
|
frames_dir = f"frames/{video_base_name}" |
|
|
flows_dir = f"optical_flows/{video_base_name}" |
|
|
|
|
|
|
|
|
frame_paths = [] |
|
|
if os.path.exists(frames_dir): |
|
|
frame_files = sorted([f for f in os.listdir(frames_dir) if f.endswith('.png')]) |
|
|
frame_paths = [os.path.join(frames_dir, f) for f in frame_files] |
|
|
|
|
|
|
|
|
flow_paths = [] |
|
|
if os.path.exists(flows_dir): |
|
|
flow_files = sorted([f for f in os.listdir(flows_dir) if f.endswith('.png')]) |
|
|
flow_paths = [os.path.join(flows_dir, f) for f in flow_files] |
|
|
|
|
|
record['frames'] = frame_paths |
|
|
record['optical_flows'] = flow_paths |
|
|
|
|
|
yield idx, record |
|
|
idx += 1 |
|
|
|