-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_tester.py
27 lines (19 loc) · 913 Bytes
/
model_tester.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
import tensorflow as tf
from data_utils import get_data, get_dataset, img_standardization, _parse_function
import math
def evaluate_model(weight_name):
batch_size = 10
x_train, y_train = get_data(aug=True, name='train')
x_test, y_test = get_data(aug=False, name='test')
num_data = len(x_test)
[x_test] = img_standardization(x_train, x_test)
x_test = _parse_function(x_test, im_size=224)
dataset_test = get_dataset(x_test, y_test, batch_size, resize=False)
model = tf.keras.models.load_model('./weight/' + weight_name, compile=True)
# because evaluate() will calculate loss and metrics['accuracy'], so recompiling the loaded model is necessary
[loss, acc] = model.evaluate(dataset_test, steps=math.ceil(num_data / batch_size))
print('TEST loss: ', loss)
print('TEST acc: ', acc)
return
if __name__ == '__main__':
evaluate_model('vgg16_ECG200_03.h5')