Skip to content

Commit 4b9ce1b

Browse files
committed
update
1 parent 0980e30 commit 4b9ce1b

14 files changed

+144
-73
lines changed

__init__.py

Whitespace-only changes.

cal_metrics.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ def default(self, obj):
2525

2626
class Cal_Metrics:
2727
def __init__(self, config):
28-
self.config = config
29-
self.source = config.source
30-
self.client_conifg = config.client
28+
self.config = config.client
29+
self.source = config.client.source
30+
self.database_config = config.client.database
3131
self.inference_config = config.server
32-
self.database_config = config.database
3332
self.large_object_detection = Object_Detection(self.inference_config, type='large inference')
3433

3534
def cal_ground_truth(self):
3635
with VideoProcessor(self.source) as video:
3736
truth_dict = {}
3837
video_fps = video.fps
39-
interval = self.client_conifg.interval
38+
interval = self.config.interval
4039
logger.info("the video fps is {}".format(video_fps))
4140
if interval == 0:
4241
logger.error("the interval error")
@@ -60,33 +59,38 @@ def cal_ground_truth(self):
6059

6160

6261
def cal_mAP(self):
63-
interval = self.client_conifg.interval
62+
interval = self.config.interval
6463
with open('truth.json', 'r') as f:
6564
ground_truths = json.load(f)
6665
# calculates the mAP for an IOU threshold of 0.5
6766
database = DataBase(self.database_config)
6867
database.use_database()
69-
result = database.select_result(self.client_conifg.edge_id)
70-
total_frame = self.config.max_count / interval
68+
result = database.select_result(self.config.edge_id)
69+
total_frame = self.source.max_count / interval
7170
sum_map = 0.0
7271
sum_delay = 0.0
7372
filtered_out = 0
7473
i = 0
7574
last_result = None
75+
logger.debug(len(result))
7676
while i < len(result):
7777
index, start_time, end_time, res, log = result[i]
7878
gap = end_time-start_time
7979
sum_delay += gap
8080
result_dict = eval(res)
81-
if 'ref' in result_dict.keys:
82-
filtered_out += 1
83-
res = result[result_dict['ref']][3]
84-
pred = eval(res)
85-
else:
81+
logger.debug(result_dict.keys())
82+
if 'lables' in result_dict.keys():
8683
pred = eval(res)
8784
last_result = pred
85+
elif 'ref' in result_dict.keys():
86+
filtered_out += 1
87+
pred = last_result
88+
else:
89+
pred = last_result
90+
logger.debug(pred)
8891
ground_truth = ground_truths['{}'.format(index)]
89-
map = calculate_map(ground_truth, pred)
92+
logger.debug(ground_truth)
93+
map = calculate_map(ground_truth, pred, 0.5)
9094
sum_map += map
9195

9296

@@ -99,14 +103,11 @@ def cal_mAP(self):
99103
config = yaml.load(f, Loader=yaml.SafeLoader)
100104
# provide class-like access for dict
101105
config = munch.munchify(config)
102-
cal_truth = True
106+
cal_truth = False
103107
cal = Cal_Metrics(config)
104-
#cal.cal_ground_truth()
105-
cal.cal_detection_result()
106-
"""
107108
if cal_truth:
108109
cal.cal_ground_truth()
109110
cal.cal_mAP()
110-
"""
111+
111112

112113

cloud_server.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def __init__(self, config):
4141
def cloud_local(self):
4242
while True:
4343
task = self.local_queue.get(block=True)
44+
if time.time() - task.start_time >= self.config.wait_thresh:
45+
end_time = time.time()
46+
task.end_time = end_time
47+
task.state = TASK_STATE.TIMEOUT
48+
self.update_table(task)
49+
continue
4450
task.frame_cloud = task.frame_edge
4551
frame = task.frame_cloud
4652
high_boxes, high_class, high_score = self.large_object_detection.large_inference(frame)
@@ -57,10 +63,15 @@ def cloud_local(self):
5763

5864

5965
def update_table(self, task):
66+
if task.state == TASK_STATE.FINISHED:
67+
state = "Finished"
68+
elif task.state == TASK_STATE.TIMEOUT:
69+
state = "Timeout"
70+
else:
71+
state = ""
6072
detection_boxes, detection_class, detection_score = task.get_result()
61-
state = "Finished" if task.state == TASK_STATE.FINISHED else ""
6273
result = {
63-
'lables': detection_class,
74+
'labels': detection_class,
6475
'boxes': detection_boxes,
6576
'scores': detection_score
6677
}

config/config.yaml

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,65 @@ client:
22
# the source video
33
source:
44
video_path: ./video_data/dayroad.mp4
5-
max_count: 120
5+
max_count: 5
66
rtsp:
77
flag: False
88
account: your account
99
password: your password
1010
ip_address: you camera ip
1111
channel: 1
12-
#the frame interval
12+
# the frame interval
1313
interval: 2
14-
#the difference feature (pixel, edge, area, corner).
14+
# the difference feature (pixel, edge, area, corner).
1515
feature: edge
16-
#the difference flag and thresh
16+
# the difference flag and thresh
1717
diff_flag: True
1818
diff_thresh: 0.01
19-
#the queue maxsize
19+
# the queue maxsize
2020
local_queue_maxsize: 10
21-
#the queue threshold for offloading
21+
# the queue threshold for offloading
2222
queue_thresh: 5
23-
#Number of worker threads to offloading thread pool
23+
# the max wait time
24+
wait_thresh: 10
25+
# Number of worker threads to offloading thread pool
2426
offloading_max_worker: 1
2527
frame_cache_maxsize: 100
2628
small_model_name: fasterrcnn_mobilenet_v3_large_fpn
27-
#select the offloading policy
28-
policy: Edge-Local
29-
#change frame resolution using frame new height
29+
# select the offloading policy
30+
policy: Edge-Shortest
31+
# change frame resolution using frame new height
3032
new_height:
31-
#offload to another edge node [1080, 720], default 720
33+
# offload to another edge node [1080, 720], default 720
3234
another: 720
33-
#option to offload directly to the cloud [1080, 720, 480], default 480
35+
# option to offload directly to the cloud [1080, 720, 480], default 480
3436
directly_cloud: 720
35-
#offload to the cloud after local inference [1080, 720, 480], default 720
37+
# offload to the cloud after local inference [1080, 720, 480], default 720
3638
local_cloud: 720
37-
#The task from another edge node is offloaded to the cloud after local inference [720, 480], default 720
39+
# The task from another edge node is offloaded to the cloud after local inference [720, 480], default 720
3840
another_cloud: 720
39-
#the quality of the transmitted frame
41+
# the quality of the transmitted frame
4042
quality:
41-
#offload to another edge node [90, 85], default 85
43+
# offload to another edge node [90, 85], default 85
4244
another: 90
43-
#Option to offload directly to the cloud [85, 95], default 85
45+
# Option to offload directly to the cloud [85, 95], default 85
4446
directly_cloud: 90
45-
#offload to the cloud after local inference [85, 95], default 95
47+
# offload to the cloud after local inference [85, 95], default 95
4648
local_cloud: 90
47-
#The task from another edge node is offloaded to the cloud after local inference, default 85.
49+
# The task from another edge node is offloaded to the cloud after local inference, default 85.
4850
another_cloud: 90
49-
#server_ip
50-
server_ip: '43.137.51.180:50051'
51-
#edge nodes
51+
# server_ip
52+
server_ip: '127.0.0.1:50051'
53+
# edge nodes
5254
edge_id: 1
53-
destinations: {'id': [2], 'ip':['127.0.0.1:50050']}
54-
#database config
55+
edge_num: 2
56+
destinations: {'id': [2], 'ip':['192.168.0.185:50050']}
57+
# database config
5558
database:
56-
connection: { 'user': 'root', 'password': 'root', 'host': '43.137.51.180', 'raise_on_warnings': True }
59+
connection: { 'user': 'root', 'password': 'root', 'host': '127.0.0.1', 'raise_on_warnings': True }
5760
database_name: 'mydatabase'
5861
# retrain
5962
retrain:
63+
flag: False
6064
num_epoch: 2
6165
cache_path: './cache'
6266
collect_num: 10
@@ -65,11 +69,12 @@ client:
6569

6670
server:
6771
server_id: 0
68-
edge_ids: [1]
72+
edge_ids: [1,2]
6973
large_model_name: fasterrcnn_resnet50_fpn
7074
#the queue maxsize
7175
local_queue_maxsize: 10
72-
data_queue_maxsize: 10
76+
# the max wait time
77+
wait_thresh: 10
7378
#database config
7479
database:
7580
connection: { 'user': 'root', 'password': 'root', 'host': '127.0.0.1', 'raise_on_warnings': True }
1.97 KB
Binary file not shown.

edge/__pycache__/info.cpython-38.pyc

666 Bytes
Binary file not shown.
680 Bytes
Binary file not shown.

edge/__pycache__/task.cpython-38.pyc

-297 Bytes
Binary file not shown.
1.22 KB
Binary file not shown.

0 commit comments

Comments
 (0)