-
Notifications
You must be signed in to change notification settings - Fork 1
/
prediction.py
executable file
·64 lines (36 loc) · 1.3 KB
/
prediction.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
61
62
63
64
import pandas as pd
from PIL import Image
import os
import numpy as np
# from keras.models import load_model
def load_test_data(dir_name, DIM):
datasets = ['a', 'b', 'c', 'd', 'e', 'f', 'auga', 'augc']
temp = np.ndarray(shape=(0, DIM, DIM, 1))
names= [ ]
for data in datasets:
cwd = os.getcwd()
os.chdir(dir_name + "/testing-{0}/".format(data))
nwd = os.getcwd( )
file_names= os.listdir(nwd)
names.append(file_names)
for i in file_names:
I = Image.open(i)
C = I.resize((DIM, DIM))
C = np.array(C.convert('L'), dtype=np.uint8).reshape((1, DIM, DIM, 1))
temp = np.concatenate((temp, C), axis=0)
os.chdir(cwd)
print(data)
flat_names = [item for sublist in names for item in sublist]
return (temp, flat_names)
def test_prediction(dir_name, DIM, model, index):
X_test, file_names= load_test_data(dir_name, DIM)
# model = load_model('CNN_6.h5')
prob = model.predict(X_test)
y_test = np.argmax(prob, axis=1).flatten()
d = {'key': file_names, 'label': y_test}
df = pd.DataFrame(data=d)
df.to_csv('prediction_'+str(index)+'.csv', index=False)
def main():
test_prediction(r"/home/pnl/Downloads/numta", DIM= 180)
if __name__== "__main__":
main( )