-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
75 lines (51 loc) · 2.08 KB
/
run.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
__author__ = "Rubén Buzón Pérez"
__email__ = "[email protected]"
import argparse
import utils
modes_classes = {
'basic': ["Neutral", "Feliz", "Triste"],
'extra': ["Neutral", "Feliz", "Triste", "Sorprendido", "Enfadado"],
}
modes_models = {
'basic': './models/emotions_3_classes.hdf5',
'extra': './models/emotions_5_classes.hdf5',
}
modes_classifiers = {
'basic': './models/haarcascade.xml',
'extra': './models/haarcascade.xml',
}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Facial emotion recognition using neural network.')
parser.add_argument('--class-mode', type=str, default='basic', choices=['basic', 'extra'], required=False,
help="""Number of classes to detect. Basic mode classifies 3 diferent emotions with 87%%
of accuracy while Extra mode classifies 5 different classes with 74%% of accuracy.""")
parser.add_argument('--input-mode', type=str, default='webcam', choices=['webcam', 'screen'], required=False,
help="""Input source to detect faces(WIP).""")
# TODO: implementar grabación de pantalla
parser.add_argument('--background', action=argparse.BooleanOptionalAction,
help="""Execute in background without window.""")
args = parser.parse_args()
model = None
model_classes = None
classifier = None
start_method = None
match args.class_mode:
case 'basic':
model = modes_models.get('basic')
model_classes = modes_classes.get('basic')
classifier = modes_classifiers.get('basic')
case 'extra':
model = modes_models.get('extra')
model_classes = modes_classes.get('extra')
classifier = modes_classifiers.get('extra')
case _:
raise ValueError(f"Invalid argument {args.class_mode} for --class-mode")
detector = utils.EmotionDetector(model=model, classifier=classifier, classes=model_classes, background=args.background)
match args.input_mode:
case 'webcam':
start_method = detector.start_webcam_detection
case 'screen':
start_method = detector.start_screen_detection
case _:
raise ValueError(f"Invalid argument {args.input_mode} for --input-mode")
start_method()