-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpresent_bench_results.py
executable file
·119 lines (93 loc) · 3.3 KB
/
present_bench_results.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import base64
import glob
import os
import sys
from pathlib import Path
from docx import Document
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.shared import Inches
from omegaconf import OmegaConf
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(parent_dir)
print(parent_dir)
from plotting_benchmark.vis_generator import read_responses
def decode_image(encoded_image, output_image_file):
decoded_image = base64.b64decode(encoded_image)
# Write the decoded image data to a file
with open(output_image_file, "wb") as image_file:
image_file.write(decoded_image)
"""
Just a script to generate a docx file to dump generated tasks and plots to verify them.
"""
do_random = False
# suffix = "_probs"
suffix = ""
if do_random and len(suffix) == 0:
suffix = "_random"
# config_path = "../configs/config.yaml"
config_path = "configs/config.yaml"
config = OmegaConf.load(config_path)
paths = config.paths
dataset_folder = Path(paths.dataset_folder)
results_folder = Path(paths.out_folder)
temp_folder = results_folder / "temp"
os.makedirs(temp_folder, exist_ok=True)
bench_file = results_folder / "benchmark_results_dev.jsonl"
response_file = results_folder / "gpt_plots_dev1.jsonl"
bench_scores = read_responses(bench_file)
plot_responses = read_responses(response_file)
temp_image_file = temp_folder / "plot.png"
# list of strings
ids = list(bench_scores.keys())
doc = Document()
section = doc.sections[0]
new_width, new_height = section.page_height, section.page_width
section.page_width = new_width
section.page_height = new_height
for idx in ids:
response = plot_responses[idx]
result = bench_scores[idx]
paragraph = doc.add_paragraph()
paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
paragraph.add_run(f"ID = {idx}\n")
score = result["score"]
if isinstance(score, int):
score_txt = f"{score:.0f}"
else:
score_txt = score
paragraph.add_run(f"Score = {score_txt}\n")
if len(result["error"]) > 0 and not do_random:
paragraph.add_run(f'Error = {result["error"]}\n')
if not do_random:
dp_folder = dataset_folder / str(idx)
else:
if "id_rnd" in result:
rnd_idx = result["id_rnd"]
else:
rnd_idx = idx
dp_folder = dataset_folder / str(rnd_idx)
paragraph.add_run("RANDOM PAIR\n")
plot_files = glob.glob(os.path.join(str(dp_folder), "*.png"))
plot_file = plot_files[0]
if len(plot_files) > 1 and not do_random:
paragraph.add_run(
f"There should be {len(plot_files)} images in GT, used only one\n"
)
table = doc.add_table(rows=1, cols=2)
table.style = "Table Grid"
cell = table.cell(0, 0)
cell.text = "Generated"
if len(response["plot results"]["images"]) > 0:
decode_image(response["plot results"]["images"][0], temp_image_file)
paragraph = cell.paragraphs[0]
run = paragraph.add_run()
run.add_picture(str(temp_image_file), width=Inches(4))
cell = table.cell(0, 1)
cell.text = "Ground truth"
paragraph = cell.paragraphs[0]
run = paragraph.add_run()
run.add_picture(plot_file, width=Inches(4))
doc.add_page_break()
result_file = results_folder / "bench_results.docx"
doc.save(result_file)
print(f"Output saved in {str(result_file)}")