-
Notifications
You must be signed in to change notification settings - Fork 0
/
evalsavedmodel.py
58 lines (52 loc) · 2.04 KB
/
evalsavedmodel.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
# from keras.datasets import mnist
# from keras.models import Sequential
# from keras.layers import Dense, Dropout, Flatten
# from keras.layers import Conv2D, MaxPooling2D
import numpy as np
import glob
np.random.seed(123)
# from tensorflow.keras.optimizers import SGD, Adam
# from tensorflow.python.keras.models import Sequential
# from tensorflow.python.keras.layers import Dense, Dropout, Activation, Flatten
# from tensorflow.python.keras.layers import Convolution2D, MaxPooling2D, ZeroPadding2D
# from tensorflow.python.keras.utils import np_utils
# from tensorflow.python.keras import backend as K
# from tensorflow.python.keras.datasets import mnist
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.utils import to_categorical
from tensorflow.python.keras.layers import Dense, Dropout, Flatten, Lambda, ELU, Activation, BatchNormalization
from tensorflow.python.keras.layers.convolutional import Convolution2D, Cropping2D, ZeroPadding2D, MaxPooling2D
import tensorflow as tf
# from keras.optimizers import SGD, Adam, RMSprop
#
# from sklearn.model_selection import train_test_split
# from sklearn.preprocessing import LabelEncoder
# import matplotlib.pyplot as plt
# import matplotlib.image as mpimg
import pickle as pkl
import time
#Setting up data
num_authors = 20
X_test = pkl.load(open("X_test.pkl", "rb"))
y_test = pkl.load(open("y_test.pkl", "rb"))
X_test = X_test.reshape(X_test.shape[0], 1, 113, 113)
X_test = X_test.astype('float32')
X_test /= 255
y_test = to_categorical(y_test, num_authors)
# Recreate the exact same model purely from the file
model = tf.keras.models.load_model('modelsave')
score = model.evaluate(X_test, y_test, verbose=0)
print(score)
np.set_printoptions(linewidth = 200)
Y_pred = model.predict(X_test)
print(Y_pred.shape)
y_pred = np.argmax(Y_pred, axis=1)
print(y_pred.shape)
y_acc = np.argmax(y_test, axis=1)
print(y_pred)
print(y_acc)
# tf.compat.v1.disable_eager_execution()
# cm = tf.math.confusion_matrix(y_acc, y_pred)
# sess = tf.compat.v1.Session()
# with sess.as_default():
# print(cm.eval())