-
Notifications
You must be signed in to change notification settings - Fork 2
/
Model_cnn_prediction_map.py
126 lines (100 loc) · 3.08 KB
/
Model_cnn_prediction_map.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from keras.utils import *
import tensorflow as tf
import numpy as np
import random
from keras.models import model_from_json
import Data_load_testdata as dlt
import Data_load_4 as dl
from sklearn.model_selection import train_test_split
import matplotlib.pylab as plt
import seaborn as sns
'''
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
'''
#modelname = input("Type Model's name :: ")
modelname = "Model_cnn_onlyPIR_ep1000"
modelname_json = "Models/" + modelname + ".json"
modelname_weight = "Models/" + modelname + ".h5"
json_file = open(modelname_json,"r")
loaded_model_json = json_file.read()
json_file.close()
model = tf.keras.models.model_from_json(loaded_model_json)
model.load_weights(modelname_weight)
print("Model Loaded...! :: " + modelname)
DataX = list()
DataY = list()
dl.Data_load("None", DataX, DataY)
dl.Data_load("Human", DataX, DataY)
dlt.Data_load("None", DataX, DataY)
dlt.Data_load("Human", DataX, DataY)
exist_none = list()
exist_exist = list()
none_none = list()
none_exist = list()
DataX = np.asarray(DataX)
DataY = np.asarray(DataY)
DataX = np.reshape(DataX, (int(DataX.__len__()/4), 4, 100))
x_data =list()
def decision(predict):
if predict[0][0] > predict[0][1]:
return "None"
else:
return "Exist"
def predict_result(x_data, result, y_data,):
global exist_exist
global exist_none
global none_exist
global none_none
#say exist , but none
if result == "Exist" and y_data[0] == 1:
exist_none.append(x_data[0])
# say exist , and exist
elif result == "Exist" and y_data[0] == 0:
exist_exist.append(x_data[0])
# say none , and none
elif result == "None" and y_data[0] == 1:
none_none.append(x_data[0])
# say none, but exist
elif result == "None" and y_data[0] == 0:
none_exist.append(x_data[0])
for i in range(len(DataX)):
x_data.append(DataX[i][0])
x_data = np.asarray(x_data)
x_data = np.reshape(x_data, (-1, 1, 10, 10))
X_train, X_test, Y_train, Y_test = train_test_split(x_data, DataY, test_size=0.3, random_state=777, shuffle=True)
for i in range(len(X_test)):
testdata = X_test[i]
testdata = np.reshape(testdata, (1, 1, 10, 10))
result = decision(model.predict(testdata))
predict_result(testdata, result, Y_test[i])
if i % 1000 == 0:
print(i)
ee = list()
en = list()
ne = list()
nn = list()
for i in range(0, 1000):
if i < len(exist_exist):
ee.append(exist_exist[i][0])
if i < len(exist_none):
en.append(exist_none[i][0])
if i < len(none_exist):
ne.append(none_exist[i][0])
if i < len(none_none):
nn.append(none_none[i][0])
print("Exist _ Exist :: " + str(len(exist_exist)))
print("Exist _ None :: " + str(len(exist_none)))
print("None _ Exist :: " + str(len(none_exist)))
print("None _ None :: " + str(len(none_none)))
#plt.title("")
for i in range(20):
print(ne[i])
for j in range(20):
print(nn[j])
sns.tsplot(data=ee, color="blue")
sns.tsplot(data=en, color="red")
#sns.tsplot(data=ne, color="black")
#sns.tsplot(data=nn, color="yellow")
plt.show()