-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_incorrect_cases.py
58 lines (48 loc) · 1.52 KB
/
view_incorrect_cases.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
import sys
import random
import numpy as np
import mayavi.mlab as mlab
import matplotlib.pyplot as plt
from data_loader import dl
test_filename = sys.argv[1]
label_filename = sys.argv[2]
predict_filename = sys.argv[3]
n_shown = 5
dl.prepare_test_data(test_filename)
labels = dl.load_label_file(label_filename)
data = np.load(predict_filename)
x = data['incorrect_cases_x']
y = data['incorrect_cases_y']
pred = data['incorrect_cases_pred']
length = x.shape[0]
random_indices = random.sample(range(0, length), n_shown)
# most_incorrect_indices = []
# for i in range(0, length):
# lowest_preds = np.argsort(y[i])[:2]
# actual_label = np.argmax(y[i])
# if actual_label in lowest_preds:
# most_incorrect_indices.append(i)
fig = plt.figure()
subplot_i = 1
for i in random_indices:
mlab.figure(size=(480, 340))
xx, yy, zz = np.where(x[i] == 1)
mlab.points3d(xx, yy, zz,
mode="cube",
color=(0, 1, 0),
scale_factor=1)
img = mlab.screenshot()
# mlab.close()
ax1 = fig.add_subplot(2, n_shown, subplot_i)
ax1.imshow(img)
ax1.set_title(labels[np.argmax(y[i])])
ax1.set_axis_off()
ax2 = fig.add_subplot(2, n_shown, subplot_i + n_shown)
sorted_pred_indices = np.argsort(pred[i])[::-1]
x_pos = np.arange(len(labels))
ax2.bar(x_pos, pred[i][sorted_pred_indices], align='center')
ax2.set_xticks(x_pos)
ax2.set_xticklabels(np.asarray(labels)[sorted_pred_indices], rotation='vertical')
subplot_i += 1
plt.tight_layout()
plt.show()