test_transformers.py 3.14 KB
Newer Older
1
import numpy as np
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
2
from bob.pipelines import Sample
3
from bob.bio.base import load_resource
4
from bob.bio.base.test.utils import is_library_available
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
5
import pytest
6

7
8

def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46, 53)}):
9
    np.random.seed(10)
10
11
12
13
14
    data = np.random.rand(3, 400, 400)
    annotations = {"leye": (115, 267), "reye": (115, 132)}
    return Sample(data, key="1", annotations=annotations)


Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
15
@pytest.mark.slow
16
@is_library_available("tensorflow")
17
def test_facenet_sanderberg():
18
    transformer = load_resource("facenet-sanderberg", "transformer")
19
20
21

    fake_sample = get_fake_sample()

22
23
24
25
26
    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
    assert transformed_sample.data.size == 128


Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
27
@pytest.mark.slow
28
@is_library_available("tensorflow")
29
def test_inception_resnetv2_msceleb():
30
    transformer = load_resource("inception-resnetv2-msceleb", "transformer")
31
32
33
34
35
36
37
38

    fake_sample = get_fake_sample()

    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
    assert transformed_sample.data.size == 128


Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
39
@pytest.mark.slow
40
@is_library_available("tensorflow")
41
def test_inception_resnetv2_casiawebface():
42
    transformer = load_resource("inception-resnetv2-casiawebface", "transformer")
43
44

    fake_sample = get_fake_sample()
45
46
47
48
49

    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
    assert transformed_sample.data.size == 128

50

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
51
@pytest.mark.slow
52
@is_library_available("tensorflow")
53
def test_inception_resnetv1_msceleb():
54
    transformer = load_resource("inception-resnetv1-msceleb", "transformer")
55
56
57
58
59
60
61
62

    fake_sample = get_fake_sample()

    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
    assert transformed_sample.data.size == 128


Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
63
@pytest.mark.slow
64
@is_library_available("tensorflow")
65
def test_inception_resnetv1_casiawebface():
66
    transformer = load_resource("inception-resnetv1-casiawebface", "transformer")
67
68
69
70
71
72

    fake_sample = get_fake_sample()

    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
    assert transformed_sample.data.size == 128
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
73

74

75
"""
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
76
77
78
def test_arcface_insight_tf():
    import tensorflow as tf
    tf.compat.v1.reset_default_graph()
79
    transformer = load_resource("arcface-insight-tf", "transformer")
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
80
81
82
83
84
85

    fake_sample = get_fake_sample()

    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
    assert transformed_sample.data.size == 512
86
"""
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
87

88

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
89
def test_gabor_graph():
90
    transformer = load_resource("gabor-graph", "transformer")
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
91
92
93
94

    fake_sample = get_fake_sample()
    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
95
    assert len(transformed_sample.data) == 80
96
97


98
def test_lgbphs():
99
100
101
102
103
    transformer = load_resource("lgbphs", "transformer")

    fake_sample = get_fake_sample()
    transformed_sample = transformer.transform([fake_sample])[0]
    transformed_data = transformed_sample.data
104
    assert transformed_sample.data.shape == (2, 44014)