test_picklability.py 2.72 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
from bob.pipelines.utils import assert_picklable
4
import numpy
5

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

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

9
10
11
12
13
14
15
16
17
18
19
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",
    )
20
    assert assert_picklable(cropper)
21
22
23
24
25
26
27
28
29


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
    )
30
    assert assert_picklable(face_detect)
31
32
33
34


def test_INormLBP():
    face_crop = bob.bio.face.preprocessor.INormLBP(face_cropper="face-crop-eyes")
35
    assert assert_picklable(face_crop)
36
37
38
39


def test_TanTriggs():
    face_crop = bob.bio.face.preprocessor.TanTriggs(face_cropper="face-crop-eyes")
40
    assert assert_picklable(face_crop)
41
42
43


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


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

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

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

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

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

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

65
def test_GridGraph():    
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
66
    extractor = bob.bio.face.extractor.GridGraph(node_distance=24)
67
68
69
70
71
72
    assert assert_picklable(extractor)

    fake_image = numpy.arange(64*80).reshape(64,80).astype("float")
    extractor(fake_image)
    assert assert_picklable(extractor)

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

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
74
75
76
    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
77
    eyes = cropper.cropped_positions
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
78
    extractor = bob.bio.face.extractor.GridGraph(eyes=eyes)
79
80
81
82
    assert assert_picklable(extractor)



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

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

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
85
86
def test_LGBPHS():
    import math
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
87

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
88
    extractor = bob.bio.face.extractor.LGBPHS(
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
89
90
91
92
93
94
        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
95
96
    )

97
    assert assert_picklable(extractor)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
98
99
100
101
102
103
104
105
106
107


## Algorithms


def test_GaborJet():

    algorithm = bob.bio.face.algorithm.GaborJet(
        "PhaseDiffPlusCanberra", multiple_feature_scoring="average_model"
    )
108
    assert assert_picklable(algorithm)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
109
110
111
112


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