-
Notifications
You must be signed in to change notification settings - Fork 2
/
service.py
61 lines (47 loc) · 1.77 KB
/
service.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
from aiohttp import web
import asyncio
from tensorflow_ssd.detection import start_detection
import threading
routes = web.RouteTableDef()
detection_thread = None
stop_event = None
@routes.post("/model/upload")
async def receive_model(request):
data = await request.post()
input_file = data['file']
model_type = data['type']
path = ""
extension = input_file.filename.split('.')[-1]
if extension == "pb":
if model_type == "face":
path = "fine_tuned_model/face/saved_model/new_face_model.pb"
elif model_type == "license_plate":
path = "fine_tuned_model/license_plate/saved_model/new_license_plate_model.pb"
elif extension == "m5":
if model_type == "face":
path = "keras-retinanet/fine_tuned_model/face/new_face_model.h5"
elif model_type == "license_plate":
path = "keras-retinanet/fine_tuned_model/license_plate/new_license_plate_model.h5"
else:
return web.Response(status=415) #Unsupported media type
with open(path, 'w+b') as f:
content = input_file.file.read()
f.write(content)
return web.Response(status=200)
@routes.post("/start")
async def start_stream(request):
global detection_thread, stop_event
data = await request.json()
stream_endpoint = data['reciever']
if detection_thread != None:
stop_event.set()
detection_thread.join()
stop_event = threading.Event()
detection_thread = threading.Thread(target=start_detection,
args=(stream_endpoint, stop_event))
detection_thread.start()
return web.Response(status=200)
if __name__ == "__main__":
app = web.Application(client_max_size=0)
app.add_routes(routes)
web.run_app(app, host='0.0.0.0', port=5000)