test_databases.py 11.1 KB
Newer Older
Manuel Günther's avatar
Manuel Günther committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# @author: Manuel Guenther <Manuel.Guenther@idiap.ch>
# @date: Thu May 24 10:41:42 CEST 2012
#
# Copyright (C) 2011-2012 Idiap Research Institute, Martigny, Switzerland
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


from nose.plugins.skip import SkipTest

import bob.bio.base
24
from bob.bio.base.test.utils import db_available
25
26
27
28
from bob.bio.base.test.test_database_implementations import (
    check_database,
    check_database_zt,
)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
29
import bob.core
30

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
31
logger = bob.core.log.setup("bob.bio.face")
Manuel Günther's avatar
Manuel Günther committed
32
33


34
35
36
def _check_annotations(
    database, topleft=False, required=True, limit_files=None, framed=False
):
37
38
    database_legacy = database.database
    files = database_legacy.all_files()
39
40
    if limit_files is not None:
        import random
41

42
        files = random.sample(files, limit_files)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
43
    found_none = False
44

45
    for file in files:
46
        annotations = database_legacy.annotations(file)
47
48
        if required:
            assert annotations is not None
49
50
        if annotations is not None:
            assert isinstance(annotations, dict)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
51
52
53
            if framed:
                # take one of the frames
                annotations = annotations[list(annotations.keys())[0]]
54
            if topleft:
55
56
                assert "topleft" in annotations
                assert "bottomright" in annotations
57
            else:
58
59
                assert "reye" in annotations
                assert "leye" in annotations
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
60
61
62
        else:
            found_none = True
    if found_none:
63
        logger.warn("Some annotations were None for {}".format(database_legacy.name))
Manuel Günther's avatar
Manuel Günther committed
64
65


66
@db_available("arface")
Manuel Günther's avatar
Manuel Günther committed
67
def test_arface():
68
    database = bob.bio.base.load_resource(
69
70
        "arface", "database", preferred_package="bob.bio.face"
    )
71
    try:
72
        check_database(database, groups=("dev", "eval"))
73
74
    except IOError as e:
        raise SkipTest(
75
76
77
            "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
78
79
80
81
    try:
        _check_annotations(database)
    except IOError as e:
        raise SkipTest(
82
83
84
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
85
86


87
@db_available("atnt")
88
def test_atnt():
89
    database = bob.bio.base.load_resource(
90
91
        "atnt", "database", preferred_package="bob.bio.face"
    )
92
93
    try:
        check_database(database)
94
95
    except IOError as e:
        raise SkipTest(
96
97
98
            "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
Manuel Günther's avatar
Manuel Günther committed
99
100


101
@db_available("gbu")
Manuel Günther's avatar
Manuel Günther committed
102
def test_gbu():
103
    database = bob.bio.base.load_resource(
104
105
        "gbu", "database", preferred_package="bob.bio.face"
    )
106
    try:
107
        check_database(database, models_depend=True)
108
109
        check_database(database, protocol="Bad", models_depend=True)
        check_database(database, protocol="Ugly", models_depend=True)
110
111
    except IOError as e:
        raise SkipTest(
112
113
114
            "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
115
116
117
118
    try:
        _check_annotations(database, limit_files=1000)
    except IOError as e:
        raise SkipTest(
119
120
121
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
122
123


124
@db_available("lfw")
Manuel Günther's avatar
Manuel Günther committed
125
def test_lfw():
126
    database = bob.bio.base.load_resource(
127
128
        "lfw-restricted", "database", preferred_package="bob.bio.face"
    )
129
    try:
130
        check_database(database, training_depends=True, models_depend=True)
131
132
133
134
135
136
137
138
139
140
141
142
143
144
        check_database(
            database,
            groups=("dev", "eval"),
            protocol="fold1",
            training_depends=True,
            models_depend=True,
        )
        check_database(
            bob.bio.base.load_resource(
                "lfw-unrestricted", "database", preferred_package="bob.bio.face"
            ),
            training_depends=True,
            models_depend=True,
        )
145
146
    except IOError as e:
        raise SkipTest(
147
148
149
            "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
150
151
152
153
    try:
        _check_annotations(database, limit_files=1000)
    except IOError as e:
        raise SkipTest(
154
155
156
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
Manuel Günther's avatar
Manuel Günther committed
157
158


159
@db_available("mobio")
Manuel Günther's avatar
Manuel Günther committed
160
def test_mobio():
161
    database = bob.bio.base.load_resource(
162
163
        "mobio-image", "database", preferred_package="bob.bio.face"
    )
164
    try:
165
        check_database_zt(database, models_depend=True)
166
167
168
169
170
171
172
173
174
175
176
177
178
        check_database_zt(database, protocol="female", models_depend=True)
        check_database_zt(
            bob.bio.base.load_resource(
                "mobio-male", "database", preferred_package="bob.bio.face"
            ),
            models_depend=True,
        )
        check_database_zt(
            bob.bio.base.load_resource(
                "mobio-female", "database", preferred_package="bob.bio.face"
            ),
            models_depend=True,
        )
179
180
    except IOError as e:
        raise SkipTest(
181
182
183
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
184
185

    try:
186
        _check_annotations(database, limit_files=1000)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
187
    except IOError as e:
188
        raise SkipTest(
189
190
191
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
Manuel Günther's avatar
Manuel Günther committed
192
193


194
@db_available("multipie")
Manuel Günther's avatar
Manuel Günther committed
195
def test_multipie():
196
    database = bob.bio.base.load_resource(
197
198
        "multipie", "database", preferred_package="bob.bio.face"
    )
199
    try:
200
        check_database_zt(database, training_depends=True)
201
202
203
204
205
206
        check_database_zt(
            bob.bio.base.load_resource(
                "multipie-pose", "database", preferred_package="bob.bio.face"
            ),
            training_depends=True,
        )
207
208
    except IOError as e:
        raise SkipTest(
209
210
211
            "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
212
213
    except ValueError as e:
        raise SkipTest(
214
215
216
            "The database could not queried; probably the protocol is missing inside the db.sql3 file. Here is the error: '%s'"
            % e
        )
217
218

    try:
219
220
        if database.database.annotation_directory is None:
            raise SkipTest("The annotation directory is not set")
221
        _check_annotations(database)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
222
    except IOError as e:
223
        raise SkipTest(
224
225
226
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
Manuel Günther's avatar
Manuel Günther committed
227
228


229
@db_available("replay")
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
230
def test_replay_licit():
231
    database = bob.bio.base.load_resource(
232
233
        "replay-img-licit", "database", preferred_package="bob.bio.face"
    )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
234
    try:
235
        check_database(database, groups=("dev", "eval"))
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
236
237
    except IOError as e:
        raise SkipTest(
238
239
240
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
241
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
242
243
        _check_annotations(database, topleft=True)
    except IOError as e:
244
        raise SkipTest(
245
246
247
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
248
249


250
@db_available("replay")
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
251
def test_replay_spoof():
252
    database = bob.bio.base.load_resource(
253
254
        "replay-img-spoof", "database", preferred_package="bob.bio.face"
    )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
255
    try:
256
        check_database(database, groups=("dev", "eval"))
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
257
258
    except IOError as e:
        raise SkipTest(
259
260
261
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
262
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
263
264
        _check_annotations(database, topleft=True)
    except IOError as e:
265
        raise SkipTest(
266
267
268
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
269
270


271
@db_available("replaymobile")
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
272
def test_replaymobile_licit():
273
    database = bob.bio.base.load_resource(
274
275
        "replaymobile-img-licit", "database", preferred_package="bob.bio.face"
    )
276
    try:
277
        check_database(database, groups=("dev", "eval"))
278
279
    except IOError as e:
        raise SkipTest(
280
281
282
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
283
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
284
285
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
286
        raise SkipTest(
287
288
289
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
290
291


292
@db_available("replaymobile")
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
293
def test_replaymobile_spoof():
294
    database = bob.bio.base.load_resource(
295
296
        "replaymobile-img-spoof", "database", preferred_package="bob.bio.face"
    )
297
    try:
298
        check_database(database, groups=("dev", "eval"))
299
300
    except IOError as e:
        raise SkipTest(
301
302
303
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
            % e
        )
304
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
305
306
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
307
        raise SkipTest(
308
309
310
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
311
312


313
@db_available("ijbc")
314
315
def test_ijbc():
    database = bob.bio.base.load_resource(
316
317
        "ijbc-11", "database", preferred_package="bob.bio.face"
    )
318
319
320
    try:
        check_database(database, models_depend=True, training_depends=True)
    except IOError as e:
321
        raise SkipTest("The database could not queried; Here is the error: '%s'" % e)
322
323
324
325
    try:
        _check_annotations(database, topleft=True, limit_files=1000)
    except IOError as e:
        raise SkipTest(
326
327
328
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
            % e
        )
329

330
331

@db_available("fargo")
332
333
def test_fargo():
    database = bob.bio.base.load_resource(
334
335
        "fargo", "database", preferred_package="bob.bio.face"
    )
336
337
338
    try:
        check_database(database)
    except IOError as e:
339
340
341
342
343
344
345
346
347
348
349
350
        raise SkipTest("The database could not queried; Here is the error: '%s'" % e)


def test_meds():
    from bob.bio.face.database import MEDSDatabase

    database = MEDSDatabase("verification_fold1")

    assert len(database.background_model_samples()) == 234

    assert len(database.references()) == 223 // 2
    assert len(database.probes()) == 313