This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoad_NN_model.py
138 lines (116 loc) · 4.47 KB
/
Load_NN_model.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
127
128
129
130
131
132
133
134
135
136
137
138
from __future__ import absolute_import, division, print_function, unicode_literals
import time
import tensorflow as tf
from tensorflow import keras
import numpy as np
from sklearn.model_selection import KFold
import matplotlib.pyplot as plt
import csv
import os
FOLDER='testResult'
start_time = time.time()
# запись векторов разрещений и результата
Y_vector=None
Permissions_vector=None
App_Names=[]
with open(FOLDER+'/permission_dict.csv', newline='') as File:
reader = csv.reader(File,delimiter=';')
for row in reader:
if reader.line_num == 1:
continue
else:
if Y_vector is None:
if row[1].find('virus') != -1:
Y_vector=np.array([1])
else:
Y_vector=np.array([0])
else:
if row[1].find('virus') != -1:
Y_vector=np.append(Y_vector,[1],axis=0)
else:
Y_vector=np.append(Y_vector,[0],axis=0)
temp = [int(i) for i in row[2:]]
if Permissions_vector is None:
Permissions_vector=np.array([temp])
else:
Permissions_vector=np.append(Permissions_vector,[temp],axis=0)
OtherDict_vector=None
with open(FOLDER+'/OtherDict.csv', newline='') as File:
reader = csv.reader(File,delimiter=';')
for row in reader:
if reader.line_num == 1:
continue
else:
temp = [int(i) for i in row[2:]]
if OtherDict_vector is None:
OtherDict_vector=np.array([temp])
else:
OtherDict_vector=np.append(OtherDict_vector,[temp],axis=0)
API_CALLS_vector=None
with open(FOLDER+'/API_CALLS.csv', newline='') as File:
reader = csv.reader(File,delimiter=';')
for row in reader:
if reader.line_num == 1:
continue
else:
temp = [int(i) for i in row[2:]]
if API_CALLS_vector is None:
API_CALLS_vector=np.array([temp])
else:
API_CALLS_vector=np.append(API_CALLS_vector,[temp],axis=0)
#API_CALLS_vector=normalize(API_CALLS_vector,axis=1)#нормализация тут- сомниельные результаты
# загрузка нормализации
temp=None
with open('API_CALLS_normalization.npy', 'rb') as f:
temp = np.load(f)
API_CALLS_vector=API_CALLS_vector/temp
groupAPI_dict_vector=None
with open(FOLDER+'/groupAPI_dict.csv', newline='') as File:
reader = csv.reader(File,delimiter=';')
for row in reader:
if reader.line_num == 1:
continue
else:
temp = [int(i) for i in row[2:]]
if groupAPI_dict_vector is None:
groupAPI_dict_vector=np.array([temp])
else:
groupAPI_dict_vector=np.append(groupAPI_dict_vector,[temp],axis=0)
#groupAPI_dict_vector=normalize(groupAPI_dict_vector,axis=1)
# загрузка нормализации
temp=None
with open('groupAPI_dict_normalization.npy', 'rb') as f:
temp = np.load(f)
groupAPI_dict_vector=groupAPI_dict_vector/temp
strings_dict_vector=None
with open(FOLDER+'/strings_dict.csv', newline='') as File:
reader = csv.reader(File,delimiter=';')
for row in reader:
if reader.line_num == 1:
continue
else:
temp = [int(i) for i in row[2:]]
if strings_dict_vector is None:
strings_dict_vector=np.array([temp])
else:
strings_dict_vector=np.append(strings_dict_vector,[temp],axis=0)
# загрузка нормализации
temp=None
with open('string_normalization.npy', 'rb') as f:
temp = np.load(f)
strings_dict_vector=strings_dict_vector/temp
result_vector=np.append(Permissions_vector,OtherDict_vector,axis=1)
result_vector=np.append(result_vector,API_CALLS_vector,axis=1)
result_vector=np.append(result_vector,groupAPI_dict_vector,axis=1)
result_vector=np.append(result_vector,strings_dict_vector,axis=1)
print("Data loaded:{} ".format(time.time() - start_time))
# Восстановим в точности ту же модель, включая веса и оптимизатор
new_model = keras.models.load_model('my_model.h5')
# Покажем архитектуру модели
new_model.summary()
# Evaluate the restored model
predictions = new_model.predict(result_vector)
#for i in predictions:
# print(f"Appp{}predictions)
print(predictions)
print("All DONE:{} ".format(time.time() - start_time))