test_databases.py 14 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('gbu')
Manuel Günther's avatar
Manuel Günther committed
131
def test_gbu():
132
133
    database = bob.bio.base.load_resource(
        'gbu', 'database', preferred_package='bob.bio.face')
134
    try:
135
136
        check_database(database, models_depend=True)
        check_database(database, protocol='Bad', models_depend=True)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
137
        check_database(database, protocol='Ugly', models_depend=True)
138
139
140
    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
141
142
143
144
145
    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)
146
147
148
149


@db_available('ijba')
def test_ijba():
150
151
    database = bob.bio.base.load_resource(
        'ijba', 'database', preferred_package='bob.bio.face')
152
    try:
153
        check_database(database,models_depend=True, training_depends=True)
154
155
156
    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
157
    try:
158
        _check_annotations(database, topleft=True, limit_files=1000)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
159
160
161
    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
162
163


164
@db_available('lfw')
Manuel Günther's avatar
Manuel Günther committed
165
def test_lfw():
166
167
    database = bob.bio.base.load_resource(
        'lfw-restricted', 'database', preferred_package='bob.bio.face')
168
    try:
169
        check_database(database, training_depends=True, models_depend=True)
170
171
        check_database(database, groups=('dev', 'eval'),
                       protocol='fold1', training_depends=True, models_depend=True)
172
173
        check_database(bob.bio.base.load_resource('lfw-unrestricted', 'database', preferred_package='bob.bio.face'),
                       training_depends=True, models_depend=True)
174
175
176
    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
177
178
179
180
181
    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
182
183


184
@db_available('mobio')
Manuel Günther's avatar
Manuel Günther committed
185
def test_mobio():
186
187
    database = bob.bio.base.load_resource(
        'mobio-image', 'database', preferred_package='bob.bio.face')
188
    try:
189
190
191
192
193
194
        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)
195
196
197
198
199
    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:
200
        _check_annotations(database, limit_files=1000)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
201
    except IOError as e:
202
203
        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
204
205


206
@db_available('multipie')
Manuel Günther's avatar
Manuel Günther committed
207
def test_multipie():
208
209
    database = bob.bio.base.load_resource(
        'multipie', 'database', preferred_package='bob.bio.face')
210
    try:
211
212
213
        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)
214
215
216
217
218
219
220
221
222
    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
223
    except IOError as e:
224
225
        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
226
227


228
@db_available('scface')
Manuel Günther's avatar
Manuel Günther committed
229
def test_scface():
230
231
    database = bob.bio.base.load_resource(
        'scface', 'database', preferred_package='bob.bio.face')
232
    try:
233
        check_database_zt(database)
234
235
236
    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)
237
238
    try:
        _check_annotations(database)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
239
    except IOError as e:
240
241
        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
242
243


244
@db_available('xm2vts')
Manuel Günther's avatar
Manuel Günther committed
245
def test_xm2vts():
246
247
    database = bob.bio.base.load_resource(
        'xm2vts', 'database', preferred_package='bob.bio.face')
248
    try:
249
        check_database(database, groups=('dev', 'eval'))
250
251
        check_database(database, groups=('dev', 'eval'),
                       protocol='darkened-lp1')
252
253
254
    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)
255
256
    try:
        _check_annotations(database)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
257
    except IOError as e:
258
259
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
260
261
262


@db_available('replay')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
263
def test_replay_licit():
264
265
    database = bob.bio.base.load_resource(
        'replay-img-licit', 'database', preferred_package='bob.bio.face')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
266
267
268
269
270
    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)
271
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
272
273
        _check_annotations(database, topleft=True)
    except IOError as e:
274
275
        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
276
277
278
279


@db_available('replay')
def test_replay_spoof():
280
281
    database = bob.bio.base.load_resource(
        'replay-img-spoof', 'database', preferred_package='bob.bio.face')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
282
283
284
285
286
    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)
287
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
288
289
        _check_annotations(database, topleft=True)
    except IOError as e:
290
291
        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
292
293
294
295


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


@db_available('replaymobile')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
311
def test_replaymobile_spoof():
312
313
    database = bob.bio.base.load_resource(
        'replaymobile-img-spoof', 'database', preferred_package='bob.bio.face')
314
315
316
317
318
    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)
319
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
320
321
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
322
323
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359


@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)