test_embeddings.py 3.27 KB
Newer Older
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import bob.bio.face
import numpy as np
from bob.pipelines import Sample, wrap

def test_facenet():
    from bob.bio.face.embeddings import FaceNetSanderberg

    np.random.seed(10)

    transformer = FaceNetSanderberg()    
    # Raw data
    data = np.random.rand(3, 160, 160).astype("uint8")
    output = transformer.transform(data)
    assert output.size == 128, output.shape
    

    # Sample Batch
    sample = Sample(data)
    transformer_sample = wrap(["sample"], transformer)
    output = [s.data for s in transformer_sample.transform([sample])][0]

    assert output.size == 128, output.shape


def test_idiap_inceptionv2_msceleb():
    from bob.bio.face.embeddings import InceptionResnetv2_MsCeleb

    np.random.seed(10)
    transformer = InceptionResnetv2_MsCeleb()
    data = np.random.rand(3, 160, 160).astype("uint8")
    output = transformer.transform(data)
    assert output.size == 128, output.shape

    # Sample Batch
    sample = Sample(data)
    transformer_sample = wrap(["sample"], transformer)
    output = [s.data for s in transformer_sample.transform([sample])][0]

    assert output.size == 128, output.shape


def test_idiap_inceptionv2_casia():
    from bob.bio.face.embeddings import InceptionResnetv2_CasiaWebFace

    np.random.seed(10)
    transformer = InceptionResnetv2_CasiaWebFace()
    data = np.random.rand(3, 160, 160).astype("uint8")
    output = transformer.transform(data)
    assert output.size == 128, output.shape


    # Sample Batch
    sample = Sample(data)
    transformer_sample = wrap(["sample"], transformer)
    output = [s.data for s in transformer_sample.transform([sample])][0]

    assert output.size == 128, output.shape


def test_idiap_inceptionv1_msceleb():
    from bob.bio.face.embeddings import InceptionResnetv1_MsCeleb

    np.random.seed(10)
    transformer = InceptionResnetv1_MsCeleb()
    data = np.random.rand(3, 160, 160).astype("uint8")
    output = transformer.transform(data)
    assert output.size == 128, output.shape

    # Sample Batch
    sample = Sample(data)
    transformer_sample = wrap(["sample"], transformer)
    output = [s.data for s in transformer_sample.transform([sample])][0]

    assert output.size == 128, output.shape


def test_idiap_inceptionv1_casia():
    from bob.bio.face.embeddings import InceptionResnetv1_CasiaWebFace

    np.random.seed(10)
    transformer = InceptionResnetv1_CasiaWebFace()
    data = np.random.rand(3, 160, 160).astype("uint8")
    output = transformer.transform(data)
    assert output.size == 128, output.shape

    # Sample Batch
    sample = Sample(data)
    transformer_sample = wrap(["sample"], transformer)
    output = [s.data for s in transformer_sample.transform([sample])][0]

    assert output.size == 128, output.shape


def test_arface_insight_tf():
    import tensorflow as tf
    tf.compat.v1.reset_default_graph()

    from bob.bio.face.embeddings import ArcFace_InsightFaceTF

    np.random.seed(10)
    transformer = ArcFace_InsightFaceTF()
    data = np.random.rand(3, 112, 112).astype("uint8")
    output = transformer.transform(data)
    assert output.size == 512, output.shape

    # Sample Batch
    sample = Sample(data)
    transformer_sample = wrap(["sample"], transformer)
    output = [s.data for s in transformer_sample.transform([sample])][0]
    assert output.size == 512, output.shape