File size: 3,052 Bytes
4599420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from pathlib import Path
import glob
import json
import csv
import tqdm
import hashlib

from convert_utils.base_convertor import BaseConvertor
from time_utils.time_utils import format_time, time_to_seconds, seconds_to_time


class PrepareBenchmarkTemplate(BaseConvertor):
    VIDEO_ROOT = "/home/dyvm6xra/dyvm6xrauser36/dyvm6xrauser36/huankguan2/Project/OmniEval/benchmarks/streamingbench/StreamingBench/videos"

    def read_data(self, data_file: str) -> list:
        with open(data_file, mode="r", encoding="utf-8") as f:
            reader = csv.DictReader(f)
            data = list(reader)
        return data

    def get_video_uuid(self, item) -> str:
        video_uuid = hashlib.sha256(
            self.get_video_path(item).encode("utf-8")
        ).hexdigest()[:8]
        return video_uuid

    def get_video_path(self, item) -> str:
        task_name, sample_name, sample_id, _ = item["question_id"].split("_")
        video_path = (
            f"{self.VIDEO_ROOT}/{task_name}/{sample_name}_{sample_id}/video.mp4"
        )
        return video_path

    def get_stream_addr(self, item) -> str:
        return f"/home/dyvm6xra/dyvm6xrauser36/dyvm6xrauser36/huankguan2/Project/OmniEval/benchmarks/streamingbench/stream_chunks/{self.get_video_uuid(item)}"
    
    def build_sqa(self, item) -> list:
        """event_id: int, timestamp: str"""
        question_t = format_time(item["time_stamp"])
        response_t = question_t

        event_ts = [question_t, response_t]

        def auto_fill_label(options):
            options = eval(options)
            for i in range(len(options)):
                p = str(chr(ord('A') + i)) + ". "
                if not options[i].startswith(p):
                    options[i] = p + options[i]
            return str(options)
        
        sqa = []
        for i, ts in enumerate(self.deduplicate_and_sorting(event_ts)):
            event = {
                "event_id": i + 1,
                "timestamp": ts,
                "question_id": item["question_id"],
            }
            if ts == question_t:
                event = event | {
                    "task_type": item["task_type"],
                    "question": item["question"],
                    "options": auto_fill_label(item["options"]),
                }
            if ts == response_t:
                event = event | {"response": item["answer"]}

            sqa.append(event)

        return sqa


inputs = [
    (
        "contextual_understanding.jsonl",
        ["StreamingBench/annotations/Contextual_Understanding.csv"],
    ),
    (
        "omni_source_understanding.jsonl",
        ["StreamingBench/annotations/Omni_Source_Understanding.csv"],
    ),
    (
        "real_time_visual_understanding.jsonl",
        ["StreamingBench/annotations/Real_Time_Visual_Understanding.csv"],
    ),
]

for outfile, samples in inputs:
    converter = PrepareBenchmarkTemplate(outfile=outfile, start_id=1)
    converter.clear()

    for x in tqdm.tqdm(samples):
        converter.convert(x)

    print("done:", outfile)