forked from ambianic/fall-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfall_prediction.py
84 lines (63 loc) · 2.43 KB
/
fall_prediction.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
import os
import time
from src.pipeline.fall_detect import FallDetector
def _fall_detect_config():
_dir = os.path.dirname(os.path.abspath(__file__))
_good_tflite_model = os.path.join(
_dir,
'ai_models/posenet_mobilenet_v1_100_257x257_multi_kpt_stripped.tflite'
)
_good_edgetpu_model = os.path.join(
_dir,
'ai_models/posenet_mobilenet_v1_075_721_1281_quant_decoder_edgetpu.tflite'
)
_good_labels = 'ai_models/pose_labels.txt'
config = {
'model': {
'tflite': _good_tflite_model,
'edgetpu': _good_edgetpu_model,
},
'labels': _good_labels,
'top_k': 3,
'confidence_threshold': 0.6,
'model_name':'mobilenet'
}
return config
def Fall_prediction(img_1,img_2,img_3=None):
config = _fall_detect_config()
result = None
fall_detector = FallDetector(**config)
def process_response(response):
nonlocal result
for res in response:
result = res['inference_result']
process_response(fall_detector.process_sample(image=img_1))
time.sleep(fall_detector.min_time_between_frames)
process_response(fall_detector.process_sample(image=img_2))
if len(result) == 1:
category = result[0]['label']
confidence = result[0]['confidence']
angle = result[0]['leaning_angle']
keypoint_corr = result[0]['keypoint_corr']
dict_res = {}
dict_res["category"] = category
dict_res["confidence"] = confidence
dict_res["angle"] = angle
dict_res["keypoint_corr"] = keypoint_corr
return dict_res
else:
if img_3:
time.sleep(fall_detector.min_time_between_frames)
process_response(fall_detector.process_sample(image=img_3))
if len(result) == 1:
category = result[0]['label']
confidence = result[0]['confidence']
angle = result[0]['leaning_angle']
keypoint_corr = result[0]['keypoint_corr']
dict_res = {}
dict_res["category"] = category
dict_res["confidence"] = confidence
dict_res["angle"] = angle
dict_res["keypoint_corr"] = keypoint_corr
return dict_res
return None