test_databases.py 7.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Thu May 24 10:41:42 CEST 2012

from nose.plugins.skip import SkipTest

import bob.bio.base
from bob.bio.base.test.utils import db_available

10

11
@db_available("replay")  # the name of the package
12
def test_replay():
13
    # replay-attack is the name of the entry point
14
    replay_database_instance = bob.bio.base.load_resource(
15
16
17
18
        "replay-attack",
        "database",
        preferred_package="bob.pad.face",
        package_prefix="bob.pad.",
19
    ).database
20
    try:
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
        assert (
            len(replay_database_instance.objects(groups=["train", "dev", "eval"]))
            == 1200
        )
        assert len(replay_database_instance.objects(groups=["train", "dev"])) == 720
        assert len(replay_database_instance.objects(groups=["train"])) == 360
        assert (
            len(
                replay_database_instance.objects(
                    groups=["train", "dev", "eval"], protocol="grandtest"
                )
            )
            == 1200
        )
        assert (
            len(
                replay_database_instance.objects(
                    groups=["train", "dev", "eval"],
                    protocol="grandtest",
                    purposes="real",
                )
            )
            == 200
        )
        assert (
            len(
                replay_database_instance.objects(
                    groups=["train", "dev", "eval"],
                    protocol="grandtest",
                    purposes="attack",
                )
            )
            == 1000
        )
56

57
58
    except IOError as e:
        raise SkipTest(
59
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
60
61
            % e
        )
62
63
64


def test_replaymobile():
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    database = bob.bio.base.load_resource(
        "replay-mobile",
        "database",
        preferred_package="bob.pad.face",
        package_prefix="bob.pad.",
    )

    assert database.protocols() == ["grandtest", "mattescreen", "print"]
    assert database.groups() == ["dev", "eval", "train"]
    assert len(database.samples(groups=["train", "dev", "eval"])) == 1030
    assert len(database.samples(groups=["train", "dev"])) == 728
    assert len(database.samples(groups=["train"])) == 312
    assert len(database.samples(groups=["train", "dev", "eval"])) == 1030
    assert (
        len(database.samples(groups=["train", "dev", "eval"], purposes="real")) == 390
    )
    assert (
        len(database.samples(groups=["train", "dev", "eval"], purposes="attack")) == 640
    )

    sample = database.sort(database.samples())[0]
86
    try:
87
88
89
90
91
92
93
94
95
96
        assert sample.annotations["0"] == {
            "bottomright": [760, 498],
            "topleft": [374, 209],
            "leye": [518, 417],
            "reye": [522, 291],
            "mouthleft": [669, 308],
            "mouthright": [666, 407],
            "nose": [585, 358],
        }
        assert sample.data.shape == (20, 3, 720, 1280)
97
    except IOError as e:
98
        raise SkipTest(e)
99
100


101
# Test the maskattack database
102
@db_available("maskattack")
103
104
def test_maskattack():
    maskattack = bob.bio.base.load_resource(
105
106
107
108
109
        "maskattack",
        "database",
        preferred_package="bob.pad.face",
        package_prefix="bob.pad.",
    ).database
110
111
    try:
        # all real sequences: 2 sessions, 5 recordings for 17 individuals
112
113
114
115
        assert (
            len(maskattack.objects(groups=["train", "dev", "eval"], purposes="real"))
            == 170
        )
116
        # all attacks: 1 session, 5 recordings for 17 individuals
117
118
119
120
        assert (
            len(maskattack.objects(groups=["train", "dev", "eval"], purposes="attack"))
            == 85
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
121

122
        # training real: 7 subjects, 2 sessions, 5 recordings
123
        assert len(maskattack.objects(groups=["train"], purposes="real")) == 70
124
        # training real: 7 subjects, 1 session, 5 recordings
125
        assert len(maskattack.objects(groups=["train"], purposes="attack")) == 35
126
127
128
129

        # dev and test contains the same number of sequences:
        # real: 5 subjects, 2 sessions, 5 recordings
        # attack: 5 subjects, 1 sessions, 5 recordings
130
131
132
133
        assert len(maskattack.objects(groups=["dev"], purposes="real")) == 50
        assert len(maskattack.objects(groups=["eval"], purposes="real")) == 50
        assert len(maskattack.objects(groups=["dev"], purposes="attack")) == 25
        assert len(maskattack.objects(groups=["eval"], purposes="attack")) == 25
134
135
136
137

    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
138
139
            % e
        )
140

141
142

# Test the casiasurf database
143
@db_available("casiasurf")
144
145
def test_casiasurf():
    casiasurf = bob.bio.base.load_resource(
146
147
148
149
150
        "casiasurf",
        "database",
        preferred_package="bob.pad.face",
        package_prefix="bob.pad.",
    ).database
151
    try:
152
153
154
155
156
157
158
159
160
161
162
163
164
        assert len(casiasurf.objects(groups=["train"], purposes="real")) == 8942
        assert len(casiasurf.objects(groups=["train"], purposes="attack")) == 20324
        assert len(casiasurf.objects(groups=("dev",), purposes=("real",))) == 2994
        assert len(casiasurf.objects(groups=("dev",), purposes=("attack",))) == 6614
        assert (
            len(casiasurf.objects(groups=("dev",), purposes=("real", "attack"))) == 9608
        )
        assert len(casiasurf.objects(groups=("eval",), purposes=("real",))) == 17458
        assert len(casiasurf.objects(groups=("eval",), purposes=("attack",))) == 40252
        assert (
            len(casiasurf.objects(groups=("eval",), purposes=("real", "attack")))
            == 57710
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
165

166
167
168
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
169
170
            % e
        )
Anjith GEORGE's avatar
Anjith GEORGE committed
171

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
172

173
@db_available("casia_fasd")
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
174
175
def test_casia_fasd():
    casia_fasd = bob.bio.base.load_resource(
176
177
178
179
180
        "casiafasd",
        "database",
        preferred_package="bob.pad.face",
        package_prefix="bob.pad.",
    ).database
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
181
182

    assert len(casia_fasd.objects()) == 600
183
184
185
186
187
188
    assert len(casia_fasd.objects(purposes="real")) == 150
    assert len(casia_fasd.objects(purposes="attack")) == 450
    assert len(casia_fasd.objects(groups=("train", "dev"))) == 240
    assert len(casia_fasd.objects(groups="train")) == 180
    assert len(casia_fasd.objects(groups="dev")) == 60
    assert len(casia_fasd.objects(groups="eval")) == 360
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
189
190

    # test annotations since they are shipped with bob.db.casia_fasd
191
    f = [f for f in casia_fasd.objects() if f.path == "train_release/1/2"][0]
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
192
    assert len(f.annotations) == 132
193
194
195
196
197
198
199
    a = f.annotations["0"]
    oracle = {
        "topleft": (102, 214),
        "bottomright": (242, 354),
        "reye": (151.0, 249.0),
        "leye": (151.0, 319.0),
    }
200
    assert a == oracle, a
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
201
202


203
@db_available("casia_fasd")
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
204
205
def test_casia_fasd_frames():
    casia_fasd = bob.bio.base.load_resource(
206
207
208
209
210
        "casiafasd",
        "database",
        preferred_package="bob.pad.face",
        package_prefix="bob.pad.",
    ).database
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
211
212
213
214
215
216
217
218

    # test frame loading if the db original files are available
    try:
        files = casia_fasd.objects()[:12]
        for f in files:
            for frame in f.frames:
                assert frame.shape == (3, 1280, 720)
                break
219
    except (IOError, RuntimeError) as e:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
220
221
222
223
        raise SkipTest(
            "The database original files are missing. To run this test run "
            "``bob config set bob.db.casia_fasd.directory "
            "/path/to/casia_fasd_files`` in a terminal to point to the "
224
225
            "original files on your computer. . Here is the error: '%s'" % e
        )