-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle_image_detection.py
More file actions
58 lines (47 loc) · 1.72 KB
/
single_image_detection.py
File metadata and controls
58 lines (47 loc) · 1.72 KB
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
"""
Detecting faces and predicts life stage on single image.
Args:
--image: path to input image
Typical use:
python single_image_detection.py --image="test.jpg"
"""
import argparse
import cv2
from face_detection_and_life_stage_classification import FaceDetectionAndLifeStageClassification
from face_detection import FaceDetection
from res10_face_detection import Res10FaceDetection
from life_stage_prediction import LifeStagePrediction
def parse_args():
"""
Parse command line arguments.
Returns:
Parsed arguments.
"""
ap = argparse.ArgumentParser()
ap.add_argument('-i', '--image', required=True, help='path to input image')
return vars(ap.parse_args())
def main():
"""
Runs face detection and life stage classification on image and shows the results.
"""
args = parse_args()
image_path = args['image']
image = cv2.imread(image_path)
image_processor = prepare_processing_engines()
processed_image = image_processor(image)
cv2.imshow('Output', processed_image)
cv2.waitKey(0)
def prepare_processing_engines():
"""
Loads all machine learning models for processing an image.
Returns:
Image processor, which detects faces on image and classify their life stage.
"""
res10_face_model = Res10FaceDetection('models/caffe/res10_300x300_ssd_iter_140000.caffemodel',
'models/caffe/deploy.prototxt')
face_detection_backend = FaceDetection(res10_face_model)
life_stage_backend = LifeStagePrediction('models/life_stage_model.h5')
image_processor = FaceDetectionAndLifeStageClassification(face_detection_backend, life_stage_backend)
return image_processor
if __name__ == '__main__':
main()