-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathfertest.py
42 lines (36 loc) · 1016 Bytes
/
fertest.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
# load json and create model
from __future__ import division
from keras.models import Sequential
from keras.layers import Dense
from keras.models import model_from_json
import numpy
import os
import numpy as np
json_file = open('fer.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("fer.h5")
print("Loaded model from disk")
truey=[]
predy=[]
x = np.load('./modXtest.npy')
y = np.load('./modytest.npy')
yhat= loaded_model.predict(x)
yh = yhat.tolist()
yt = y.tolist()
count = 0
for i in range(len(y)):
yy = max(yh[i])
yyt = max(yt[i])
predy.append(yh[i].index(yy))
truey.append(yt[i].index(yyt))
if(yh[i].index(yy)== yt[i].index(yyt)):
count+=1
acc = (count/len(y))*100
#saving values for confusion matrix and analysis
np.save('truey', truey)
np.save('predy', predy)
print("Predicted and true label values saved")
print("Accuracy on test set :"+str(acc)+"%")