-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_h5.py
40 lines (33 loc) · 1.03 KB
/
test_h5.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
# Importing the os library
import os
import time
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import Model, load_model
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow.keras
from PIL import Image, ImageOps
#set classes names
classes_names = ['animals', 'other', 'person']
print("#load model")
model = tensorflow.keras.models.load_model('mobilenetv2.h5')
#load image and change size to 299*299
img_path = 'image.jpg'
img = image.load_img(img_path, target_size=(299, 299))
#convert image to array
x = image.img_to_array(img)
x /= 255
x = np.expand_dims(x, axis=0)
i = 1
while i <= 100:
#predict class for image
prediction = model.predict(x)
classes = np.argmax(prediction, axis = 1)
#print class for image
print("#predict class number: ", classes, " ,is class name: ", classes_names[classes[0]], sep='')
#show time
named_tuple = time.localtime()
time_string = time.strftime("%m/%d/%Y, %H:%M:%S", named_tuple)
print(time_string)
i += 1