-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualize_precision_recall.py
137 lines (92 loc) · 4.58 KB
/
visualize_precision_recall.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import json
import glob
import os
import argparse
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--logdir", type=str,
default="/home/btrabucco/semantic-search-policy/policy-val/")
parser.add_argument("--title", type=str, default="")
args = parser.parse_args()
all_df = [pd.read_csv(f, index_col=0) for f in
glob.glob(os.path.join(args.logdir, "results/*.csv"))]
sizes = pd.concat(all_df).groupby("type").mean()["size"]
sizes = sizes.replace(to_replace=0, value=sizes.max()).sort_values()
print(sizes)
all_objects = []
all_objects_recall = []
all_objects_precision = []
objects_moved_accuracy = pd.DataFrame(columns=["Object", "Success"])
objects_to_move_accuracy = pd.DataFrame(columns=["Object", "Success"])
for json_name in glob.glob(
os.path.join(args.logdir, "results/*.json")):
with open(json_name, "r") as f:
data = json.load(f)
if "unshuffle/objects_moved" not in data.keys() or \
"unshuffle/objects_to_move" not in data.keys():
continue # certain runs may not have logged this info
for i, object_name in enumerate(data["unshuffle/objects_moved"]):
if object_name not in all_objects:
all_objects.append(object_name)
if all_objects_precision not in all_objects:
all_objects_precision.append(object_name)
objects_moved_accuracy = objects_moved_accuracy.append(
dict(Object=object_name, Success=float(data[
"unshuffle/objects_moved_accuracy"][i])), ignore_index=True)
for i, object_name in enumerate(data["unshuffle/objects_to_move"]):
if object_name not in all_objects:
all_objects.append(object_name)
if all_objects_recall not in all_objects:
all_objects_recall.append(object_name)
objects_to_move_accuracy = objects_to_move_accuracy.append(
dict(Object=object_name, Success=float(data[
"unshuffle/objects_to_move_accuracy"][i])), ignore_index=True)
aggregated = pd.concat([
objects_moved_accuracy,
objects_to_move_accuracy]).groupby("Object").mean()
all_objects = [x for x in list(sizes.index) if x in all_objects]
matplotlib.rc('font', family='Times New Roman', serif='cm10')
matplotlib.rc('mathtext', fontset='cm')
plt.rcParams['text.usetex'] = False
fig, axs = plt.subplots(2, 1, figsize=(20, 10))
axis = sns.barplot(x="Object", y="Success", linewidth=4, order=[
n if n in all_objects_recall else "" for n in all_objects],
data=objects_to_move_accuracy, ci=68, ax=axs[0])
axis.set(xlabel=None)
axis.set(ylabel=None)
axis.spines['right'].set_visible(False)
axis.spines['top'].set_visible(False)
axis.xaxis.set_ticks_position('bottom')
axis.yaxis.set_ticks_position('left')
axis.yaxis.set_tick_params(labelsize=16)
axis.xaxis.set_tick_params(labelsize=16, labelrotation=90)
axis.set_ylabel("Recall", fontsize=24,
fontweight='bold', labelpad=12)
axis.set_title(f"Which Map Differences (Small → Large) Are Detected{args.title}?",
fontsize=24, fontweight='bold', pad=12)
axis.grid(color='grey', linestyle='dotted', linewidth=2)
axis = sns.barplot(x="Object", y="Success", linewidth=4, order=[
n if n in all_objects_precision else "" for n in all_objects],
data=objects_moved_accuracy, ci=68, ax=axs[1])
axis.set(xlabel=None)
axis.set(ylabel=None)
axis.spines['right'].set_visible(False)
axis.spines['top'].set_visible(False)
axis.xaxis.set_ticks_position('bottom')
axis.yaxis.set_ticks_position('left')
axis.yaxis.set_tick_params(labelsize=16)
axis.xaxis.set_tick_params(labelsize=16, labelrotation=90)
axis.set_ylabel("Precision", fontsize=24,
fontweight='bold', labelpad=12)
axis.set_title(f"Which Detections (Small → Large) Are Correct{args.title}?",
fontsize=24, fontweight='bold', pad=12)
axis.grid(color='grey', linestyle='dotted', linewidth=2)
plt.tight_layout(pad=3.0)
plt.savefig(os.path.join(args.logdir,
"precision_recall.pdf"))
plt.savefig(os.path.join(args.logdir,
"precision_recall.png"))