test_picklability.py 2.49 KB
Newer Older
1
import bob.bio.face
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
2
import bob.bio.base
3
4
from bob.pipelines.utils import assert_picklable

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
5
### Preprocessors
6

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
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
def test_face_crop():
    CROPPED_IMAGE_HEIGHT = 64
    CROPPED_IMAGE_WIDTH = 64
    RIGHT_EYE_POS = (16.0, 15.5)
    LEFT_EYE_POS = (16.0, 48.0)
    cropper = bob.bio.face.preprocessor.FaceCrop(
        cropped_image_size=(CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
        cropped_positions={"leye": LEFT_EYE_POS, "reye": RIGHT_EYE_POS},
        color_channel="rgb",
        dtype="uint8",
    )
    assert_picklable(cropper)


def test_face_detect():
    face_detect = bob.bio.face.preprocessor.FaceDetect(face_cropper="face-crop-eyes")
    assert_picklable(face_detect)

    face_detect = bob.bio.face.preprocessor.FaceDetect(
        face_cropper="face-crop-eyes", use_flandmark=True
    )
    assert_picklable(face_detect)


def test_INormLBP():
    face_crop = bob.bio.face.preprocessor.INormLBP(face_cropper="face-crop-eyes")
    assert_picklable(face_crop)


def test_TanTriggs():
    face_crop = bob.bio.face.preprocessor.TanTriggs(face_cropper="face-crop-eyes")
    assert_picklable(face_crop)


def test_SQI():
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
43
44
45
    face_crop = bob.bio.face.preprocessor.SelfQuotientImage(
        face_cropper="face-crop-eyes"
    )
46
47
48
49
    assert_picklable(face_crop)


def test_HistogramEqualization():
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
50
51
52
    face_crop = bob.bio.face.preprocessor.HistogramEqualization(
        face_cropper="face-crop-eyes"
    )
53
    assert_picklable(face_crop)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
54

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
55

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
56
57
### Extractors

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
58

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
59
60
61
62
def test_DCT():
    extractor = bob.bio.face.extractor.DCTBlocks()
    assert_picklable(extractor)

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
63

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
64
def test_GridGraph():
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
65
    extractor = bob.bio.face.extractor.GridGraph(node_distance=24)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
66
67
    assert_picklable(extractor)

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
68
69
70
    cropper = bob.bio.base.load_resource(
        "face-crop-eyes", "preprocessor", preferred_package="bob.bio.face"
    )
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
71
    eyes = cropper.cropped_positions
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
72
    extractor = bob.bio.face.extractor.GridGraph(eyes=eyes)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
73
74
    assert_picklable(extractor)

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
75

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
76
77
def test_LGBPHS():
    import math
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
78

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
79
    extractor = bob.bio.face.extractor.LGBPHS(
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
80
81
82
83
84
85
        block_size=8,
        block_overlap=0,
        gabor_directions=4,
        gabor_scales=2,
        gabor_sigma=math.sqrt(2.0) * math.pi,
        sparse_histogram=True,
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
86
87
88
    )

    assert_picklable(extractor)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104


## Algorithms


def test_GaborJet():

    algorithm = bob.bio.face.algorithm.GaborJet(
        "PhaseDiffPlusCanberra", multiple_feature_scoring="average_model"
    )
    assert_picklable(algorithm)


def test_Histogram():
    algorithm = bob.bio.face.algorithm.Histogram()
    assert_picklable(algorithm)