-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeras_run.py
More file actions
46 lines (35 loc) · 1.33 KB
/
Copy pathkeras_run.py
File metadata and controls
46 lines (35 loc) · 1.33 KB
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
from model_def import load_model
from keras import backend as K
import numpy as np
from keras.preprocessing.image import ImageDataGenerator, img_to_array, array_to_img, load_img
from PIL import Image
img_width, img_height = 256, 256
if K.image_data_format() == 'channels_first':
input_shape = (3, img_width, img_height)
else:
input_shape = (img_width, img_height, 3)
model = load_model(input_shape, "11.h5")
img = load_img('bottle_new.jpg').resize((img_width, img_height), Image.ANTIALIAS) # this is a PIL image
x = img_to_array(img) # this is a Numpy array with shape (3, 256, 256)
x = x.reshape((1,) + x.shape)
img_gen = ImageDataGenerator().flow(x)
for x in img_gen:
print(model.predict(x))
break
train_gen = ImageDataGenerator().flow_from_directory('data/binary', target_size = (img_width, img_height), batch_size=1,
#save_to_dir='preview/trash', save_prefix='generated', save_format='jpeg',
class_mode='binary'
)
inc = 0
correct = 0
for i in train_gen:
prediction = model.predict(np.array(i[0]))
print(str(prediction) + ", " + str(i[1]))
if (prediction[0][0] >= 0.5 and i[1]):
correct = correct + 1
elif i[1] == 0:
correct = correct + 1
inc = inc + 1
if (inc >= 300):
break
print("Correct: " + str(correct))