-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTesting.py
60 lines (48 loc) · 1.36 KB
/
Testing.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
import os
import numpy as np
from keras.preprocessing.image import load_img, img_to_array
from keras.models import load_model
import time
start = time.time()
# Define Path
model_path = './models/model.h5'
test_path = 'data/test_image'
# Load the pre-trained models
model = load_model(model_path)
# Define image parameters
img_width, img_height = 150, 150
# Prediction Function
def predict(file):
x = load_img(file, target_size=(img_width, img_height))
x = img_to_array(x)
x = np.expand_dims(x, axis=0)
array = model.predict(x)
result = array[0]
# print(result)
answer = np.argmax(result)
if answer == 0:
print("Sepertinya si kucing")
elif answer == 1:
print("Sepertinya si mobil")
elif answer == 2:
print("Sepertinya si motor")
return answer
# Walk the directory for every image
for i, ret in enumerate(os.walk(test_path)):
for i, filename in enumerate(ret[2]):
if filename.startswith("."):
continue
print(ret[0] + '/' + filename)
result = predict(ret[0] + '/' + filename)
print(" ")
# Calculate execution time
end = time.time()
dur = end - start
if dur < 60:
print("Execution Time:", dur, "seconds")
elif 60 < dur < 3600:
dur = dur / 60
print("Execution Time:", dur, "minutes")
else:
dur = dur / (60 * 60)
print("Execution Time:", dur, "hours")