File size: 1,685 Bytes
17eab04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from collections import defaultdict

def transform_ovo_to_movienet_format(input_file, output_file):
    """
    将 ovo_bench_new.json 转换为类似 movienet_oe.json 的格式
    
    规则:
    1. 按 video 分组,将同一视频的问答合并到 conversations 列表
    2. 过滤掉 task 为 "REC", "SSR", "CRR" 的样本
    3. 保留每个样本的其他 keys
    """
    # 读取原始数据
    with open(input_file, 'r', encoding='utf-8') as f:
        data = json.load(f)
    
    # 过滤掉指定的 task 类型
    filtered_data = [
        item for item in data 
        if item.get('task') not in ['REC', 'SSR', 'CRR']
    ]
    
    print(f"原始样本数: {len(data)}")
    print(f"过滤后样本数: {len(filtered_data)}")
    
    new_data = []
    for sample_dict in filtered_data:
        new_dict = {}
        new_dict['video_id'] = sample_dict['id']
        new_dict['video_path'] = 'data/ovobench/videos/' + sample_dict['video']
        new_dict['task'] = sample_dict['task']
        new_dict['conversations'] = []
        conv = {
            "question": sample_dict['question'],
            "answer": sample_dict['options'][sample_dict['gt']],
            "choices": sample_dict['options'],
            "end_time": sample_dict['realtime'],
        }
        new_dict['conversations'].append(conv)
        new_data.append(new_dict)
    
    with open(output_file, 'w', encoding='utf-8') as f:
        json.dump(new_data, f, ensure_ascii=False, indent=4)
        
if __name__ == "__main__":
    input_file = "ovo_bench_new.json"
    output_file = "ovobench_formatted.json"
    
    transform_ovo_to_movienet_format(input_file, output_file)