svm_frames.py 929 Bytes
Newer Older
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
1
2
3
import bob.pipelines as mario
from bob.pad.face.transformer import VideoToFrames
from sklearn.model_selection import GridSearchCV
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
4
from sklearn.pipeline import Pipeline
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from sklearn.svm import SVC

preprocessor = globals().get("preprocessor")
extractor = globals().get("extractor")

# Classifier #
frame_cont_to_array = VideoToFrames()

param_grid = [
    {
        "C": [2 ** P for P in range(-3, 14, 2)],
        "gamma": [2 ** P for P in range(-15, 0, 2)],
        "kernel": ["rbf"],
    },
]

21

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
22
23
classifier = GridSearchCV(SVC(), param_grid=param_grid, cv=3)
classifier = mario.wrap(
24
    ["sample"], classifier, fit_extra_arguments=[("y", "is_bonafide")],
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
25
26
27
28
)


# Pipeline #
29
30
31
32
33
34
35
36
37
38
frames_classifier = Pipeline(
    [("frame_cont_to_array", frame_cont_to_array), ("classifier", classifier)]
)
pipeline = Pipeline(
    [
        ("preprocessor", preprocessor),
        ("extractor", extractor),
        ("svm", frames_classifier),
    ]
)