-
Notifications
You must be signed in to change notification settings - Fork 0
/
edge_server_main.py
70 lines (57 loc) · 2.15 KB
/
edge_server_main.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
import argparse
import cv2
import torchvision.transforms as transforms
import torch
import time
from PIL import Image
from models.vgg16 import vgg16
from models.tiny_yolo import tinyYolo
from communication import serverCommunication
WINDOW_NAME = 'CameraDemo'
def parse_args():
# Parse input arguments
desc = 'ANS in edge server side'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--dnn', dest='dnn_model',
help='vgg, yolo',
default='vgg', type=str)
parser.add_argument('--host', dest='host',
help='Ip address',
default='127.0.0.1', type=str)
parser.add_argument('--port', dest='port',
help='Ip port',
default=8080, type=int)
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
print('Called with args:')
print(args)
print('OpenCV version: {}'.format(cv2.__version__))
if args.dnn_model == 'vgg':
model = vgg16()
model.eval()
else:
model = tinyYolo()
model.eval()
#model.cuda()
communication = serverCommunication(args.host, args.port)
while True:
try:
conn, addr = communication.accept_conn()
with conn:
recv_data = communication.receive_msg(conn)
#print('receive data from mobile device !!!')
partition_point = recv_data[0]
data = recv_data[1]
data = torch.autograd.Variable(data)
#prediction = model(data.cuda(), server=True, partition=partition_point)
start_time2 = time.time()
prediction = model(data, server=True, partition=partition_point)
end_time2= time.time()
#print('partition point', partition_point, end_time2-start_time2)
print(partition_point, ',', end_time2-start_time2)
res = prediction.data
msg = communication.send_msg(conn, res)
except KeyboardInterrupt or TypeError or OSError:
communication.close_channel()