-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathALLOpenVINO.py
139 lines (107 loc) · 3.9 KB
/
ALLOpenVINO.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
139
#########################################################################################################
#
# Organization: Asociacion De Investigacion En Inteligencia Artificial Para La Leucemia Peter Moss
# Research Project: Peter Moss Acute Myeloid & Lymphoblastic Leukemia AI Research Project
# Repository: oneAPI Acute Lymphoblastic Leukemia Classifier
# Project: OneAPI OpenVINO Raspberry Pi 4 Acute Lymphoblastic Leukemia Classifier
#
# Author: Adam Milton-Barker (AdamMiltonBarker.com)
#
# Title: ALLOpenVINO RPI 4
# Description: Core class for the OneAPI Raspberry Pi 4 Acute Lymphoblastic Leukemia Classifier.
# License: MIT License
# Last Modified: 2020-10-02
#
#########################################################################################################
import psutil
import signal
import requests
import sys
import threading
from threading import Thread
from Classes.Helpers import Helpers
from Classes.iotJumpWay import Device as iot
from Classes.OpenVINO import OpenVINO
from Classes.Server import Server
class ALLOpenVINO():
""" ALLOpenVINO RPI 4
Core class for the OneAPI OpenVINO Raspberry Pi 4 Acute Lymphoblastic Leukemia Classifier.
"""
def __init__(self):
""" Initializes the class. """
self.Helpers = Helpers("Core")
self.Core = OpenVINO()
self.Helpers.logger.info("Class initialization complete.")
def iotJumpWayConn(self):
# Initiates the iotJumpWay connection class
self.iot = iot()
self.iot.connect()
def life(self):
""" Sends vital statistics to HIAS """
cpu = psutil.cpu_percent()
mem = psutil.virtual_memory()[2]
hdd = psutil.disk_usage('/').percent
tmp = psutil.sensors_temperatures()['cpu_thermal'][0].current
r = requests.get('http://ipinfo.io/json?token=' +
self.Helpers.confs["iotJumpWay"]["ipinfo"])
data = r.json()
location = data["loc"].split(',')
self.Helpers.logger.info("GeniSysAI Life (TEMPERATURE): " + str(tmp) + "\u00b0")
self.Helpers.logger.info("GeniSysAI Life (CPU): " + str(cpu) + "%")
self.Helpers.logger.info("GeniSysAI Life (Memory): " + str(mem) + "%")
self.Helpers.logger.info("GeniSysAI Life (HDD): " + str(hdd) + "%")
self.Helpers.logger.info("GeniSysAI Life (LAT): " + str(location[0]))
self.Helpers.logger.info("GeniSysAI Life (LNG): " + str(location[1]))
# Send iotJumpWay notification
self.iot.channelPub("Life", {
"CPU": str(cpu),
"Memory": str(mem),
"Diskspace": str(hdd),
"Temperature": str(tmp),
"Latitude": "",
"Longitude": ""
})
threading.Timer(300.0, self.life).start()
def do_classify(self):
""" Loads model and classifies test data """
self.Core.test_classifier()
def do_server(self):
""" Loads the API server """
self.Server = Server(self.Core, self.iot)
self.Server.start()
def do_http_classify(self):
""" Loads model and classifies test data """
self.Core.test_http_classifier()
def threading(self):
""" Creates required module threads. """
# Life thread
threading.Timer(10.0, self.life).start()
def signal_handler(self, signal, frame):
self.Helpers.logger.info("Disconnecting")
self.iot.disconnect()
sys.exit(1)
ALLOpenVINO = ALLOpenVINO()
def main():
# Starts threading
signal.signal(signal.SIGINT, ALLOpenVINO.signal_handler)
signal.signal(signal.SIGTERM, ALLOpenVINO.signal_handler)
ALLOpenVINO.threading()
if len(sys.argv) < 2:
print("You must provide an argument")
exit()
elif sys.argv[1] not in ALLOpenVINO.Helpers.confs["cnn"]["core"]:
print("Mode not supported! Server, Train or Classify")
exit()
mode = sys.argv[1]
if mode == "Classify":
""" Runs the classifier locally."""
ALLOpenVINO.do_classify()
elif mode == "Server":
""" Runs the classifier in server mode."""
ALLOpenVINO.iotJumpWayConn()
ALLOpenVINO.do_server()
elif mode == "Client":
""" Runs the classifier in client mode. """
ALLOpenVINO.do_http_classify()
if __name__ == "__main__":
main()