-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure_item-pair_gallery.py
78 lines (51 loc) · 3.03 KB
/
figure_item-pair_gallery.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
import pathlib
import matplotlib.pyplot as plt
from benchmarking.distance_benchmark import run_image_vs_image_experiment, imagenet_cases, log_git_versions, plot_saliency_map_on_image, run_image_captioning_experiment, image_captioning_cases
from benchmarking.Config import original_config_options as config
image_size = 224
half_image_size = image_size / 2
fancy_figure_kwargs = {
# much fun with DPI, column width and font size (and font type of course!)
# ... once we know these things
'alpha': 0.7
}
base_output_folder = pathlib.Path('paper_figures')
def make_image_vs_image_figure():
fig, ax = plt.subplots(2, 3, figsize=(12, 7), layout="constrained")
for ix, case in enumerate(imagenet_cases):
output_folder = base_output_folder / f'{config.experiment_name}'
output_folder.mkdir(exist_ok=True, parents=True)
config.to_yaml_file(output_folder / 'config.yml')
log_git_versions(output_folder)
case_folder = output_folder / f'image_vs_image_{case.name}'
case_folder.mkdir(exist_ok=True, parents=True)
saliency, central_value, input_image = run_image_vs_image_experiment(case, config, case_folder, analyse=False)
ax_ix = ax.flatten()[ix]
plot_saliency_map_on_image(input_image, saliency[0], ax=ax_ix,
title="", add_value_limits_to_title=False,
vmin=saliency[0].min(), vmax=saliency[0].max(),
central_value=central_value, **fancy_figure_kwargs)
ax_ix.text(half_image_size, image_size + 20, case.name,
horizontalalignment='center', verticalalignment='center')
fig.savefig(base_output_folder / 'item-pair_image_vs_image_gallery.pdf')
def make_image_vs_caption_figure():
fig, ax = plt.subplots(4, 3, figsize=(12, 14), layout="constrained")
for ix, case in enumerate(image_captioning_cases):
output_folder = base_output_folder / f'{config.experiment_name}'
output_folder.mkdir(exist_ok=True, parents=True)
config.to_yaml_file(output_folder / 'config.yml')
log_git_versions(output_folder)
case_folder = output_folder / f'image_vs_caption_{case.name}'
case_folder.mkdir(exist_ok=True, parents=True)
saliency, central_value, input_image = run_image_captioning_experiment(case, config, case_folder, analyse=False)
ax_ix = ax.flatten()[ix]
plot_saliency_map_on_image(input_image, saliency[0], ax=ax_ix,
title="", add_value_limits_to_title=False,
vmin=saliency[0].min(), vmax=saliency[0].max(),
central_value=central_value, **fancy_figure_kwargs)
ax_ix.text(half_image_size, image_size + 20, case.name,
horizontalalignment='center', verticalalignment='center')
fig.savefig(base_output_folder / 'item-pair_image_vs_caption_gallery.pdf')
if __name__ == '__main__':
# make_image_vs_image_figure()
make_image_vs_caption_figure()