lyx97 commited on
Commit
0846cf7
1 Parent(s): e76c991

Update merge_eval_result.py

Browse files
Files changed (1) hide show
  1. merge_eval_result.py +44 -11
merge_eval_result.py CHANGED
@@ -1,14 +1,47 @@
1
- import json, os
2
 
3
- eval_result_path = "file/example_eval_results"
4
- eval_result_files = [f for f in os.listdir(eval_result_path) if f.endswith('.json') and not 'merge' in f]
 
5
 
6
- merged_result = {}
7
- for fn in eval_result_files:
8
- task_type = fn.replace('.json', '')
9
- with open(f"{eval_result_path}/{fn}", "r") as f:
10
- merged_result[task_type] = json.load(f)
11
 
12
- merge_file = f"{eval_result_path}/merged_result.json"
13
- with open(merge_file, "w") as f:
14
- json.dump(merged_result, f, indent=4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json, os, argparse
2
 
3
+ def save_json(json_dict, fname):
4
+ with open(fname, "w") as f:
5
+ json.dump(json_dict, f, indent=4)
6
 
7
+ def load_json(fname):
8
+ with open(fname, "r") as f:
9
+ json_dict = json.load(f)
10
+ return json_dict
 
11
 
12
+ def merge(eval_result_path):
13
+ eval_result_files = [f for f in os.listdir(eval_result_path) if f.endswith('.json') and not 'merge' in f]
14
+ merged_result = {}
15
+ for fn in eval_result_files:
16
+ if 'tempcompass' in fn:
17
+ task_type = fn.replace('.json', '').replace('tempcompass_', '')
18
+ if task_type=='multi_choice':
19
+ task_type = 'multi-choice'
20
+ lmms_results = load_json(f"{eval_result_path}/{fn}")
21
+ results = {}
22
+ for lmms_result in lmms_results['logs']:
23
+ vid = lmms_result['doc']['video_id']
24
+ dim = lmms_result['doc']['dim']
25
+ if vid not in results:
26
+ results[vid] = {}
27
+ if dim not in results[vid]:
28
+ results[vid][dim] = []
29
+
30
+ result = lmms_result['avg_accuracy']
31
+ result.pop('video_id')
32
+ result.pop('dim')
33
+ results[vid][dim].append(result)
34
+ merged_result[task_type] = results
35
+ else:
36
+ task_type = fn.replace('.json', '')
37
+ merged_result[task_type] = load_json(f"{eval_result_path}/{fn}")
38
+
39
+ merge_file = f"{eval_result_path}/merged_result.json"
40
+ save_json(merged_result, merge_file)
41
+
42
+ if __name__ == "__main__":
43
+ parser = argparse.ArgumentParser()
44
+ parser.add_argument("--eval_result_path", type=str, default="file/example_eval_results")
45
+ args = parser.parse_args()
46
+
47
+ merge(args.eval_result_path)