test_databases.py 14.6 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
from bob.bio.base.test.test_database_implementations import check_database, check_database_zt
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
26
27
import bob.core
logger = bob.core.log.setup("bob.bio.face")
Manuel Günther's avatar
Manuel Günther committed
28
29


Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
30
def _check_annotations(database, topleft=False, required=True, limit_files=None, framed=False):
31
32
33
34
    files = database.all_files()
    if limit_files is not None:
        import random
        files = random.sample(files, limit_files)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
35
    found_none = False
36
    for file in files:
37
        annotations = database.annotations(file)
38
39
        if required:
            assert annotations is not None
40
41
        if annotations is not None:
            assert isinstance(annotations, dict)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
42
43
44
            if framed:
                # take one of the frames
                annotations = annotations[list(annotations.keys())[0]]
45
46
47
48
49
50
            if topleft:
                assert 'topleft' in annotations
                assert 'bottomright' in annotations
            else:
                assert 'reye' in annotations
                assert 'leye' in annotations
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
51
52
53
54
        else:
            found_none = True
    if found_none:
        logger.warn("Some annotations were None for {}".format(database.name))
Manuel Günther's avatar
Manuel Günther committed
55
56


57
@db_available('arface')
Manuel Günther's avatar
Manuel Günther committed
58
def test_arface():
59
60
    database = bob.bio.base.load_resource(
        'arface', 'database', preferred_package='bob.bio.face')
61
    try:
62
63
64
65
        check_database(database, groups=('dev', 'eval'))
    except IOError as e:
        raise SkipTest(
            "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
66
67
68
69
70
    try:
        _check_annotations(database)
    except IOError as e:
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
71
72
73
74


@db_available('atnt')
def test_atnt():
75
76
    database = bob.bio.base.load_resource(
        'atnt', 'database', preferred_package='bob.bio.face')
77
78
    try:
        check_database(database)
79
80
81
    except IOError as e:
        raise SkipTest(
            "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
82
83


84
@db_available('banca')
Manuel Günther's avatar
Manuel Günther committed
85
def test_banca():
86
87
    database = bob.bio.base.load_resource(
        'banca', 'database', preferred_package='bob.bio.face')
88
    try:
89
        check_database_zt(database)
90
91
92
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
93
94
95
96
97
    try:
        _check_annotations(database)
    except IOError as e:
        raise SkipTest(
            "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
98
99


100
@db_available('caspeal')
Manuel Günther's avatar
Manuel Günther committed
101
def test_caspeal():
102
103
    database = bob.bio.base.load_resource(
        'caspeal', 'database', preferred_package='bob.bio.face')
104
    try:
105
106
        check_database(database)
        check_database(database, protocol='aging')
107
108
109
    except IOError as e:
        raise SkipTest(
            "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
110
111
112
113
114
    try:
        _check_annotations(database)
    except IOError as e:
        raise SkipTest(
            "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
115
116


117
#@db_available('frgc')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
118
# def test_frgc():
119
120
121
122
123
124
125
126
127
#    import xml.sax
#    database = bob.bio.base.load_resource('frgc', 'database', preferred_package='bob.bio.face')
#    try:
#        _check_database(database, models_depend=True)
#        _check_database(database, protocol='2.0.2', models_depend=True)
#        _check_annotations(database)
#    except xml.sax.SAXException as e:
#        raise SkipTest(
#            "The database could not be opened, probably the original directory is wrong. Here is the error: '%s'" % e)
Manuel Günther's avatar
Manuel Günther committed
128

129
130
@db_available('cuhk_cufs')
def test_cuhk_cufs():
131
132
    database = bob.bio.base.load_resource(
        'cuhk_cufs', 'database', preferred_package='bob.bio.face')
133
134
135
136
137
    try:
        check_database(database)
    except IOError as e:
        raise SkipTest(
            "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
138
139
140
141
142
    try:
        _check_annotations(database)
    except IOError as e:
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
143

Manuel Günther's avatar
Manuel Günther committed
144

145
@db_available('gbu')
Manuel Günther's avatar
Manuel Günther committed
146
def test_gbu():
147
148
    database = bob.bio.base.load_resource(
        'gbu', 'database', preferred_package='bob.bio.face')
149
    try:
150
151
        check_database(database, models_depend=True)
        check_database(database, protocol='Bad', models_depend=True)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
152
        check_database(database, protocol='Ugly', models_depend=True)
153
154
155
    except IOError as e:
        raise SkipTest(
            "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
156
157
158
159
160
    try:
        _check_annotations(database, limit_files=1000)
    except IOError as e:
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
161
162
163
164


@db_available('ijba')
def test_ijba():
165
166
    database = bob.bio.base.load_resource(
        'ijba', 'database', preferred_package='bob.bio.face')
167
    try:
168
        check_database(database,models_depend=True, training_depends=True)
169
170
171
    except IOError as e:
        raise SkipTest(
            "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
172
    try:
173
        _check_annotations(database, topleft=True, limit_files=1000)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
174
175
176
    except IOError as e:
        raise SkipTest(
            "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
177
178


179
@db_available('lfw')
Manuel Günther's avatar
Manuel Günther committed
180
def test_lfw():
181
182
    database = bob.bio.base.load_resource(
        'lfw-restricted', 'database', preferred_package='bob.bio.face')
183
    try:
184
        check_database(database, training_depends=True, models_depend=True)
185
186
        check_database(database, groups=('dev', 'eval'),
                       protocol='fold1', training_depends=True, models_depend=True)
187
188
        check_database(bob.bio.base.load_resource('lfw-unrestricted', 'database', preferred_package='bob.bio.face'),
                       training_depends=True, models_depend=True)
189
190
191
    except IOError as e:
        raise SkipTest(
            "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
192
193
194
195
196
    try:
        _check_annotations(database, limit_files=1000)
    except IOError as e:
        raise SkipTest(
            "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
197
198


199
@db_available('mobio')
Manuel Günther's avatar
Manuel Günther committed
200
def test_mobio():
201
202
    database = bob.bio.base.load_resource(
        'mobio-image', 'database', preferred_package='bob.bio.face')
203
    try:
204
205
206
207
208
209
        check_database_zt(database, models_depend=True)
        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)
210
211
212
213
214
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)

    try:
215
        _check_annotations(database, limit_files=1000)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
216
    except IOError as e:
217
218
        raise SkipTest(
            "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
219
220


221
@db_available('multipie')
Manuel Günther's avatar
Manuel Günther committed
222
def test_multipie():
223
224
    database = bob.bio.base.load_resource(
        'multipie', 'database', preferred_package='bob.bio.face')
225
    try:
226
227
228
        check_database_zt(database, training_depends=True)
        check_database_zt(bob.bio.base.load_resource('multipie-pose', 'database', preferred_package='bob.bio.face'),
                          training_depends=True)
229
230
231
232
233
234
235
236
237
    except IOError as e:
        raise SkipTest(
            "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
    except ValueError as e:
        raise SkipTest(
            "The database could not queried; probably the protocol is missing inside the db.sql3 file. Here is the error: '%s'" % e)

    try:
        _check_annotations(database)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
238
    except IOError as e:
239
240
        raise SkipTest(
            "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
241
242


243
@db_available('scface')
Manuel Günther's avatar
Manuel Günther committed
244
def test_scface():
245
246
    database = bob.bio.base.load_resource(
        'scface', 'database', preferred_package='bob.bio.face')
247
    try:
248
        check_database_zt(database)
249
250
251
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
252
253
    try:
        _check_annotations(database)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
254
    except IOError as e:
255
256
        raise SkipTest(
            "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
257
258


259
@db_available('xm2vts')
Manuel Günther's avatar
Manuel Günther committed
260
def test_xm2vts():
261
262
    database = bob.bio.base.load_resource(
        'xm2vts', 'database', preferred_package='bob.bio.face')
263
    try:
264
        check_database(database, groups=('dev', 'eval'))
265
266
        check_database(database, groups=('dev', 'eval'),
                       protocol='darkened-lp1')
267
268
269
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
270
271
    try:
        _check_annotations(database)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
272
    except IOError as e:
273
274
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
275
276
277


@db_available('replay')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
278
def test_replay_licit():
279
280
    database = bob.bio.base.load_resource(
        'replay-img-licit', 'database', preferred_package='bob.bio.face')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
281
282
283
284
285
    try:
        check_database(database, groups=('dev', 'eval'))
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
286
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
287
288
        _check_annotations(database, topleft=True)
    except IOError as e:
289
290
        raise SkipTest(
            "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
291
292
293
294


@db_available('replay')
def test_replay_spoof():
295
296
    database = bob.bio.base.load_resource(
        'replay-img-spoof', 'database', preferred_package='bob.bio.face')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
297
298
299
300
301
    try:
        check_database(database, groups=('dev', 'eval'))
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
302
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
303
304
        _check_annotations(database, topleft=True)
    except IOError as e:
305
306
        raise SkipTest(
            "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
307
308
309
310


@db_available('replaymobile')
def test_replaymobile_licit():
311
312
    database = bob.bio.base.load_resource(
        'replaymobile-img-licit', 'database', preferred_package='bob.bio.face')
313
314
    try:
        check_database(database, groups=('dev', 'eval'))
315
316
317
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
318
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
319
320
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
321
322
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
323
324
325


@db_available('replaymobile')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
326
def test_replaymobile_spoof():
327
328
    database = bob.bio.base.load_resource(
        'replaymobile-img-spoof', 'database', preferred_package='bob.bio.face')
329
330
331
332
333
    try:
        check_database(database, groups=('dev', 'eval'))
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
334
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
335
336
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
337
338
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374


@db_available('msu_mfsd_mod')
def test_msu_mfsd_mod_licit():
    database = bob.bio.base.load_resource(
        'msu-mfsd-mod-licit', 'database', preferred_package='bob.bio.face')
    try:
        check_database(database, groups=('dev', 'eval'))
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is "
            "missing. Here is the error: '%s'" % e)
    try:
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
        raise SkipTest(
            "The annotations could not be queried; probably the annotation "
            "files are missing. Here is the error: '%s'" % e)


@db_available('msu_mfsd_mod')
def test_msu_mfsd_mod_spoof():
    database = bob.bio.base.load_resource(
        'msu-mfsd-mod-spoof', 'database', preferred_package='bob.bio.face')
    try:
        check_database(database, groups=('dev', 'eval'))
    except IOError as e:
        raise SkipTest(
            "The database could not be queried; probably the db.sql3 file is "
            "missing. Here is the error: '%s'" % e)
    try:
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
        raise SkipTest(
            "The annotations could not be queried; probably the annotation "
            "files are missing. Here is the error: '%s'" % e)