-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_VGG16_Test.py
40 lines (34 loc) · 1.17 KB
/
6_VGG16_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
import os
from tensorflow.keras import models
from tensorflow.keras.preprocessing import image
# Setting up directory
base_dir = os.path.dirname(os.path.abspath(__file__))
base_dir = os.path.join(base_dir, 'data')
test_dir = os.path.join(base_dir, 'test')
# test data generator
test_datagen = image.ImageDataGenerator(rescale=1./255)
test_generator = test_datagen.flow_from_directory(
test_dir,
target_size=(150, 150),
class_mode='binary',
shuffle=False
)
# load model
model = models.load_model('VGG16.h5')
print(model.summary())
# Evaluate Model using test generator
test_loss, test_acc = model.evaluate(test_generator)
print(test_acc)
# Predict probablities of model using test generator
probabilities = model.predict(test_generator)
print(test_generator.class_indices)
# Print error cases
err = 0
for i, prob in enumerate(probabilities):
if (prob > 0.5) and ('cat' in test_generator.filenames[i]):
print(test_generator.filenames[i])
err += 1
if (prob < 0.5) and ('dog' in test_generator.filenames[i]):
err += 1
print(test_generator.filenames[i])
print(err)