-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_keras.py
33 lines (24 loc) · 916 Bytes
/
test_keras.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
from keras.applications import MobileNetV2
from keras import backend as K
import cv2, os
import numpy as np
import time
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
IMAGE_SIZE = (128, 128)
WEIGHTS_FINAL = 'pretrained.h5'
#define the network
model = MobileNetV2(input_shape=(128, 128, 3), weights=None, include_top=True, classes=10)
model.load_weights(WEIGHTS_FINAL, by_name=True, skip_mismatch=True)
image_dir = 'test_split/airplane/'
image_names = os.listdir(image_dir)
print(image_names[1])
start =time.time()
for name in image_names:
image =cv2.imread(image_dir+name)
image = cv2.resize(image, (128,128))
np_image_data = np.asarray(image)
np_final = np.expand_dims(np_image_data,axis=0)
predict = model.predict(np_final)
class_name = class_names[np.argmax(predict)]
print(class_name)
print(time.time()-start)