| 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) |
| |
| |
| 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) |