File size: 1,825 Bytes
6073e55
23fdbc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) 2025 Ye Liu. Licensed under the BSD-3-Clause License.

import nncore
from torch.utils.data import Dataset

from videomind.dataset.hybrid import DATASETS
from videomind.utils.parser import parse_query, parse_question


@DATASETS.register(name='longvideobench')
class LongVideoBenchDataset(Dataset):

    ANNO_PATH_VALID = 'data/longvideobench/lvb_val.json'
    ANNO_PATH_TEST = 'data/longvideobench/lvb_test_wo_gt.json'

    VIDEO_ROOT = 'data/longvideobench/videos_3fps_480_noaudio'

    @classmethod
    def load_annos(self, split='valid'):
        if split == 'valid':
            raw_annos = nncore.load(self.ANNO_PATH_VALID)
        else:
            print('WARNING: Test split does not have ground truth annotations')
            raw_annos = nncore.load(self.ANNO_PATH_TEST)

        annos = []
        for raw_anno in raw_annos:
            vid = raw_anno['video_id']

            if vid.startswith('@'):
                vid = vid[-19:]

            # videos might come from youtube or other sources
            assert len(vid) in (11, 19)

            anno = dict(
                source='longvideobench',
                data_type='multimodal',
                video_path=nncore.join(self.VIDEO_ROOT, vid + '.mp4'),
                query=parse_query(raw_anno['question']),
                question=parse_question(raw_anno['question']),
                options=raw_anno['candidates'],
                task=str(raw_anno['duration_group']),
                level=raw_anno['level'],
                question_category=raw_anno['question_category'])

            if 'correct_choice' in raw_anno:
                anno['answer'] = raw_anno['candidates'][raw_anno['correct_choice']]
                anno['ans'] = chr(ord('A') + raw_anno['correct_choice'])

            annos.append(anno)

        return annos