test_databases.py 13 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')
    try:
61
62
63
64
        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
65
66
67
68
69
    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)
70
71
72
73
74
75
76


@db_available('atnt')
def test_atnt():
    database = bob.bio.base.load_resource('atnt', 'database', preferred_package='bob.bio.face')
    try:
        check_database(database)
77
78
79
    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
80
81


82
@db_available('banca')
Manuel Günther's avatar
Manuel Günther committed
83
def test_banca():
84
85
    database = bob.bio.base.load_resource('banca', 'database', preferred_package='bob.bio.face')
    try:
86
        check_database_zt(database)
87
88
89
    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
90
91
92
93
94
    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
95
96


97
@db_available('caspeal')
Manuel Günther's avatar
Manuel Günther committed
98
def test_caspeal():
99
100
    database = bob.bio.base.load_resource('caspeal', 'database', preferred_package='bob.bio.face')
    try:
101
102
        check_database(database)
        check_database(database, protocol='aging')
103
104
105
    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
106
107
108
109
110
    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
111
112


113
#@db_available('frgc')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
114
# def test_frgc():
115
116
117
118
119
120
121
122
123
#    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
124

125
126
127
128
129
130
131
132
@db_available('cuhk_cufs')
def test_cuhk_cufs():
    database = bob.bio.base.load_resource('cuhk_cufs', 'database', preferred_package='bob.bio.face')
    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
133
134
135
136
137
    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)
138

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

140
@db_available('gbu')
Manuel Günther's avatar
Manuel Günther committed
141
def test_gbu():
142
143
    database = bob.bio.base.load_resource('gbu', 'database', preferred_package='bob.bio.face')
    try:
144
145
        check_database(database, models_depend=True)
        check_database(database, protocol='Bad', models_depend=True)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
146
        check_database(database, protocol='Ugly', models_depend=True)
147
148
149
    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
150
151
152
153
154
    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)
155
156
157
158
159
160
161


@db_available('ijba')
def test_ijba():
    database = bob.bio.base.load_resource('ijba', 'database', preferred_package='bob.bio.face')
    try:
        check_database(database)
162
163
164
    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
165
166
167
168
169
    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
170
171


172
@db_available('lfw')
Manuel Günther's avatar
Manuel Günther committed
173
def test_lfw():
174
175
    database = bob.bio.base.load_resource('lfw-restricted', 'database', preferred_package='bob.bio.face')
    try:
176
177
178
179
        check_database(database, training_depends=True, models_depend=True)
        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)
180
181
182
    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
183
184
185
186
187
    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
188
189


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


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


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


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


@db_available('replay')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
264
265
266
267
268
269
270
def test_replay_licit():
    database = bob.bio.base.load_resource('replay-img-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)
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
280
281
282
283
284
285


@db_available('replay')
def test_replay_spoof():
    database = bob.bio.base.load_resource('replay-img-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)
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
295


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


@db_available('replaymobile')
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
309
310
def test_replaymobile_spoof():
    database = bob.bio.base.load_resource('replaymobile-img-spoof', 'database', preferred_package='bob.bio.face')
311
312
313
314
315
    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)
316
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
317
318
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
319
320
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)