| import json,os |
| import numpy as np |
|
|
| def load_multiple_json(file_path): |
| """读取包含多个 JSON 对象的文件,并将每个 JSON 对象解析成 Python 对象,存放在列表中。""" |
| with open(file_path, 'r', encoding='utf-8') as f: |
| content = f.read() |
| |
| decoder = json.JSONDecoder() |
| pos = 0 |
| results = [] |
| content_length = len(content) |
| |
| while pos < content_length: |
| |
| while pos < content_length and content[pos].isspace(): |
| pos += 1 |
| if pos >= content_length: |
| break |
| try: |
| obj, new_pos = decoder.raw_decode(content, pos) |
| results.append(obj) |
| pos = new_pos |
| except json.JSONDecodeError as e: |
| |
| print(f"JSON 解析错误: {e}") |
| break |
| return results |
|
|
|
|
|
|
| eval_file = '/root/videollm-online/data/estp_dataset/estpSqa_ours/LIVE_IT0.95.json' |
| eval_model = 'VideollmOnline' |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
|
|
| parent_dir = os.path.dirname(eval_file) |
| eval_files = [os.path.join(parent_dir, f) for f in os.listdir(parent_dir) if f.startswith(eval_file.split('/')[-1])] |
| eval_result = {} |
| for eval_file in eval_files: |
| eval_result.update(json.load(open(eval_file))) |
|
|
| task2number = { |
| "Object Recognition": 0, |
| "Attribute Perception": 0, |
| "Text-Rich Understanding": 0, |
| "Object Localization": 0, |
| "Object State Change Recognition": 0, |
| "Ego Object Localization": 0, |
| "Ego Object State Change Recognition": 0, |
| "Action Recognition": 0, |
| "Object Function": 0, |
| "Information Function": 0, |
| "Action Reasoning": 0, |
| "Task Understanding": 0, |
| |
| } |
|
|
| task2score = { |
| "Object Recognition": 0, |
| "Attribute Perception": 0, |
| "Text-Rich Understanding": 0, |
| "Object Localization": 0, |
| "Object State Change Recognition": 0, |
| "Ego Object Localization": 0, |
| "Ego Object State Change Recognition": 0, |
| "Action Recognition": 0, |
| "Object Function": 0, |
| "Information Function": 0, |
| "Action Reasoning": 0, |
| "Task Understanding": 0, |
| |
| |
| } |
|
|
| task2recall = { |
| "Object Recognition": 0, |
| "Attribute Perception": 0, |
| "Text-Rich Understanding": 0, |
| "Object Localization": 0, |
| "Object State Change Recognition": 0, |
| "Ego Object Localization": 0, |
| "Ego Object State Change Recognition": 0, |
| "Action Recognition": 0, |
| "Object Function": 0, |
| "Information Function": 0, |
| "Action Reasoning": 0, |
| "Task Understanding": 0, |
| |
| |
| } |
|
|
| task2recall_score = { |
| "Object Recognition": 0, |
| "Attribute Perception": 0, |
| "Text-Rich Understanding": 0, |
| "Object Localization": 0, |
| "Object State Change Recognition": 0, |
| "Ego Object Localization": 0, |
| "Ego Object State Change Recognition": 0, |
| "Action Recognition": 0, |
| "Object Function": 0, |
| "Information Function": 0, |
| "Action Reasoning": 0, |
| "Task Understanding": 0, |
| |
| |
| } |
|
|
| task2nonrecall_pred = { |
| "Object Recognition": 0, |
| "Attribute Perception": 0, |
| "Text-Rich Understanding": 0, |
| "Object Localization": 0, |
| "Object State Change Recognition": 0, |
| "Ego Object Localization": 0, |
| "Ego Object State Change Recognition": 0, |
| "Action Recognition": 0, |
| "Object Function": 0, |
| "Information Function": 0, |
| "Action Reasoning": 0, |
| "Task Understanding": 0, |
| |
| } |
|
|
|
|
|
|
|
|
| total_fps_last = 0 |
| total_fps = 0 |
| total_response_number = 0 |
| total_kv_cache_size = 0 |
| for k,v in eval_result.items(): |
| for kk,vv in v.items(): |
| for ll in vv: |
| if eval_model in ll.keys(): |
| for response in ll[eval_model]: |
| if response['role'] == 'fps': |
| total_fps_last+=response['content'] |
| if response['role'].lower() == 'assistant': |
| if 'fps' in response: |
| total_fps+=response['fps'] |
| total_response_number += 1 |
| if 'kv_cache_size' in response: |
| total_kv_cache_size+=response['kv_cache_size'] |
| task2number[ll['Task Type'].strip()] += 1 |
|
|
| print('total_qa: ', sum(task2number.values())) |
| print(f"Average FPS: {total_fps/total_response_number}") |
| print(f"Average KV Cache: {total_kv_cache_size/total_response_number}") |
| print("total_fps_last_mean: ", total_fps_last / sum(task2number.values())) |
| print(f"Average Response Number: {total_response_number/sum(task2number.values())}") |