-
Notifications
You must be signed in to change notification settings - Fork 9
/
node-selector.py
executable file
·80 lines (64 loc) · 2.09 KB
/
node-selector.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
#!/usr/bin/python3
####################################################################################
#
# Copyright (c) 2018 Thanasis Vergoulis & Konstantinos Zagganas & Loukas Kavouras
# for the Information Management Systems Institute, "Athena" Research Center.
#
# This file is part of SCHeMa.
#
# SCHeMa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SCHeMa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <https://www.gnu.org/licenses/>.
#
####################################################################################
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
import sys
import numpy as np
import pickle
import subprocess
modelFileName=sys.argv[1]
scalerFileName=sys.argv[2]
jobFileName=sys.argv[3]
classes={0:'thin-node',1:'medium-node'}
# Read model from pickle file
modelFile=open(modelFileName,'rb')
model=pickle.load(modelFile)
modelFile.close()
scalerFile=open(scalerFileName,'rb')
scaler=pickle.load(scalerFile)
scalerFile.close()
# Read feature values from file
jobFile=open(jobFileName,'r')
lines=[]
for line in jobFile:
line=line.strip()
if line!='':
lines.append(line)
# print(lines)
jobFile.close()
if len(lines)>1:
exit(10)
line=lines[0].split('|')
features=[]
for feature in line:
if feature.isnumeric():
features.append(int(feature))
features=[features]
# Transform arrays in numpy format
X = np.array(features)
#Scale according to the paramters calculated during model training
X_std = (X - scaler['min']) / (scaler['max'] - scaler['min'])
X= X_std * (1 - 0) + 0
result=model.predict(X)
nodeType=classes[result[0]]
print(nodeType)