-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluation_test.py
61 lines (51 loc) · 1.45 KB
/
evaluation_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from keras.models import model_from_json
from Interpreter import Interpreter
from Graphs import Graphs
import numpy as np
from sklearn.metrics import accuracy_score
if __name__ == "__main__":
"""
Evaluates model based on test dataset,
from .json and .h5 models.
"""
TARGET_SIZE = (128, 128)
BATCH_SIZE = 32
EPOCHS = 50
IMAGE_SHAPE = (128, 128, 1)
inter = Interpreter(
BATCH_SIZE,
IMAGE_SHAPE,
EPOCHS,
TARGET_SIZE
)
train_images, validation_images, test_images = inter.split_data()
# Load .json file and create model.
json_file = open('model_simple.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# Load weights.
loaded_model.load_weights('model_simple.h5')
loaded_model.compile(
loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy']
)
pred = loaded_model.predict(
test_images
)
pred[pred <= 0.5] = 0
pred[pred > 0.5] = 1
print(accuracy_score(
test_images.classes,
pred
))
graphs = Graphs()
graphs.show_confusion_matrix(
test_images.classes,
# train_images.classes,
pred,
np.array(['glaucoma', 'healthy'])
)
# TODO: Represents ROC curve could be better...
# Ref.: https://github.com/GustavoMourao/heart_dis_classify/blob/master/metric_eval_response_ROC.py