-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpredict.py
43 lines (35 loc) · 1.22 KB
/
predict.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
# SWAMI KARUPPASWAMI THUNNAI
import glob
import csv
import numpy as np
from keras.models import load_model
def initialize():
with open("dataset/header.txt", "r") as file:
headers = file.readlines()
headers = [header.strip() for header in headers]
headers = list(filter(None, headers))
return headers
def predict(file):
global classifier
row = [0 for i in range(len(headers))]
with open(file, "r") as func_file:
functions = func_file.readlines()
functions = [function.strip() for function in functions]
functions = list(filter(None, functions))
if len(functions) > 5:
for function in functions:
if function[-1] == "W":
function = function[:-1]
elif function[-2] == "A":
function = function[:-1]
try:
row[headers.index(function)] = 1
except ValueError:
pass
return classifier.predict_classes(np.array([row]))[0]
if __name__ == "__main__":
classifier = load_model("adam.h5")
headers = initialize()
files = glob.glob("dataset/test/*.txt")
for file in files:
print(predict(file))