-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest7_0519.py
69 lines (54 loc) · 1.92 KB
/
test7_0519.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
from datetime import datetime, timedelta
import time
from influxdb import InfluxDBClient
from copy import deepcopy
from influxdb import DataFrameClient
import pandas as pd
import numpy as np
from tflite_runtime.interpreter import Interpreter
def get_ifdb(db,host='localhost',port=8086, user='root', passwd='root'):
client = DataFrameClient(host, port, user, passwd, db)
client2 = InfluxDBClient(host, port, user, passwd, db)
result = client2.query('select * from networkintrusion')
df = pd.DataFrame(result)
#print(df)
try:
print('Connection Successful')
print('=========================')
print(' Connection Info')
print('=========================')
print('host;', host)
print('port:', port)
print('username:', user)
print('database:', db)
except:
print('Connection Failed')
pass
return client
mydb=get_ifdb(db='kdd5')
ifdb=mydb
result = ifdb.query('select * from networkintrusion')
result_onerow=result['networkintrusion'].iloc[1,:]
print(result_onerow)
########################################
import pandas as pd
import numpy as np
from tflite_runtime.interpreter import Interpreter
model_path='/home/pi/tesr/model3_prune_0519_quant.tflite' #prune+quant model
data_path='/home/pi/bin_data/bin_data.csv'
test_set=pd.read_csv(data_path)
test_set.drop(test_set.columns[0], axis=1, inplace=True)
x=test_set.iloc[0:,0:93]
interpreter = Interpreter(model_path=model_path)
interpreter.allocate_tensors()
#input/output tensor set
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
output_list=[]
test_features=np.expand_dims(result_onerow, axis=0)
interpreter.set_tensor(input_details[0]['index'], test_features.astype(np.float32))
interpreter.invoke()
#output get
output_data=interpreter.get_tensor(output_details[0]['index'])
output_list.append(output_data[0])
print(output_list)