-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscore.py
47 lines (38 loc) · 1.36 KB
/
score.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
from tensorflow import keras
from tensorflow.keras.models import load_model
from tensorflow.keras.datasets import cifar10
import numpy as np
import sys
def score(modelfile):
# Load the CIFAR10 data.
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
num_classes = 10
# Input image dimensions.
input_shape = x_train.shape[1:]
# Normalize data.
x_train = x_train.astype('float32') / 255
x_test = x_test.astype('float32') / 255
subtract_pixel_mean = True
# If subtract pixel mean is enabled
if subtract_pixel_mean:
x_train_mean = np.mean(x_train, axis=0)
x_train -= x_train_mean
x_test -= x_train_mean
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')
print('y_train shape:', y_train.shape)
# Convert class vectors to binary class matrices.
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)
model = load_model(modelfile)
# preds = model.predict(x)
# print(preds)
# Score trained model.
scores = model.evaluate(x_test, y_test, verbose=1)
print('Test loss:', scores[0])
print('Test accuracy:', scores[1])
if __name__ == '__main__':
modelfile = sys.argv[1]
print("score model: ", modelfile)
score(modelfile)