File size: 2,982 Bytes
82b9cde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Dataset loading script for HuggingFace
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()),  # All frames as sequence
                "optical_flows": datasets.Sequence(datasets.Image()),  # All flows as sequence
                "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)
                
                # Get paths to all frames and flows
                video_base_name = record['video_name'].replace('.mp4', '')
                frames_dir = f"frames/{video_base_name}"
                flows_dir = f"optical_flows/{video_base_name}"
                
                # Collect all frame paths
                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]
                
                # Collect all flow paths
                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