-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
39 lines (30 loc) · 1.3 KB
/
test.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
import time
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.datasets import mnist
import matplotlib.pyplot as plt
def evaluate():
(x_train, _), (x_test, _) = mnist.load_data()
# load json and create model
encoder = load_model('./tmp/encoder.h5', compile=False)
decoder = load_model('./tmp/decoder.h5', compile=False)
n = 10 # how many digits we will display
fix, ax = plt.subplots(10, 11, figsize=(17, 18), dpi=100)
for i in range(n):
index = np.random.randint(0, 10000)
x_single_test = np.array(x_test[index]).flatten() / 256
ax[i][0].imshow(np.array(x_test[index]).reshape(28, 28), cmap="gray_r")
ax[i][0].set_xticks([])
ax[i][0].set_yticks([])
for axis in ['top', 'bottom', 'left', 'right']:
ax[i][0].spines[axis].set_linewidth(3)
for j in range(10):
encoded_img = encoder.predict([np.array([x_single_test, ]), np.array([np.eye(10)[j]], )])
decoded_img = decoder.predict(encoded_img[2])
ax[i][j + 1].imshow(decoded_img[0].reshape(28, 28), cmap="gray_r")
ax[i][j + 1].set_xticks([])
ax[i][j + 1].set_yticks([])
plt.savefig("./test_results/" + str(int(time.time())) + ".png")
plt.show()
evaluate()