-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.py
More file actions
43 lines (32 loc) · 927 Bytes
/
test2.py
File metadata and controls
43 lines (32 loc) · 927 Bytes
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
from PIL import Image
import os
import numpy as np
from keras.models import load_model
from keras.preprocessing import image
from keras import backend as K
K.set_image_dim_ordering('th')
from matplotlib import pyplot
model = load_model('my_model.h5')
imgs = os.listdir('./pics')
num = len(imgs)
def get_result(numofimg, cla):
global imgs
with open('./result.txt', 'a') as f:
f.write(imgs[numofimg] + '\t' + str(cla) +'\n')
pass
for i in range(num):
img = image.load_img('./pics/'+ imgs[i], target_size=(32, 32))
#pyplot.imshow(img)
#pyplot.show()
img = image.img_to_array(img)
img = img.astype('float32')
img = img/255.0
arr = np.expand_dims(img, axis=0)
pre = model.predict(arr)
pre1 = np.argmax(pre)
pre1 = pre1.astype('int')
print(pre1)
get_result(i,pre1)
# get_result(imgs[0])
#img = image.img_to_array(img)
#arr = np.expand_dims(img, axis=0)