test_databases.py 11.4 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
    database_legacy = database.database
    files = database_legacy.all_files()
33
34
35
    if limit_files is not None:
        import random
        files = random.sample(files, limit_files)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
36
    found_none = False
37

38
    for file in files:
39
        annotations = database_legacy.annotations(file)
40
41
        if required:
            assert annotations is not None
42
43
        if annotations is not None:
            assert isinstance(annotations, dict)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
44
45
46
            if framed:
                # take one of the frames
                annotations = annotations[list(annotations.keys())[0]]
47
48
49
50
51
52
            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
53
54
55
        else:
            found_none = True
    if found_none:
56
        logger.warn("Some annotations were None for {}".format(database_legacy.name))
Manuel Günther's avatar
Manuel Günther committed
57
58


59
@db_available('arface')
Manuel Günther's avatar
Manuel Günther committed
60
def test_arface():
61
62
    database = bob.bio.base.load_resource(
        'arface', 'database', preferred_package='bob.bio.face')
63
    try:
64
65
66
67
        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
68
69
70
71
72
    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)
73
74
75
76


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


86
@db_available('gbu')
Manuel Günther's avatar
Manuel Günther committed
87
def test_gbu():
88
89
    database = bob.bio.base.load_resource(
        'gbu', 'database', preferred_package='bob.bio.face')
90
    try:
91
92
        check_database(database, models_depend=True)
        check_database(database, protocol='Bad', models_depend=True)
Amir Mohammadi's avatar
Amir Mohammadi committed
93
        check_database(database, protocol='Ugly', models_depend=True)
94
95
96
    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
97
98
99
100
101
    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)
102
103


104
@db_available('lfw')
Manuel Günther's avatar
Manuel Günther committed
105
def test_lfw():
106
107
    database = bob.bio.base.load_resource(
        'lfw-restricted', 'database', preferred_package='bob.bio.face')
108
    try:
109
        check_database(database, training_depends=True, models_depend=True)
110
111
        check_database(database, groups=('dev', 'eval'),
                       protocol='fold1', training_depends=True, models_depend=True)
112
113
        check_database(bob.bio.base.load_resource('lfw-unrestricted', 'database', preferred_package='bob.bio.face'),
                       training_depends=True, models_depend=True)
114
115
116
    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
117
118
119
120
121
    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
122
123


124
@db_available('mobio')
Manuel Günther's avatar
Manuel Günther committed
125
def test_mobio():
126
127
    database = bob.bio.base.load_resource(
        'mobio-image', 'database', preferred_package='bob.bio.face')
128
    try:
129
130
131
132
133
134
        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)
135
136
137
138
139
    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:
140
        _check_annotations(database, limit_files=1000)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
141
    except IOError as e:
142
143
        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
144
145


146
@db_available('multipie')
Manuel Günther's avatar
Manuel Günther committed
147
def test_multipie():
148
149
    database = bob.bio.base.load_resource(
        'multipie', 'database', preferred_package='bob.bio.face')
150
    try:
151
152
153
        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)
154
155
156
157
158
159
160
161
162
    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
163
    except IOError as e:
164
165
        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
166
167


168
@db_available('replay')
Amir Mohammadi's avatar
Amir Mohammadi committed
169
def test_replay_licit():
170
171
    database = bob.bio.base.load_resource(
        'replay-img-licit', 'database', preferred_package='bob.bio.face')
Amir Mohammadi's avatar
Amir Mohammadi committed
172
173
174
175
176
    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)
177
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
178
179
        _check_annotations(database, topleft=True)
    except IOError as e:
180
181
        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
182
183
184
185


@db_available('replay')
def test_replay_spoof():
186
187
    database = bob.bio.base.load_resource(
        'replay-img-spoof', 'database', preferred_package='bob.bio.face')
Amir Mohammadi's avatar
Amir Mohammadi committed
188
189
190
191
192
    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)
193
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
194
195
        _check_annotations(database, topleft=True)
    except IOError as e:
196
197
        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
198
199
200
201


@db_available('replaymobile')
def test_replaymobile_licit():
202
203
    database = bob.bio.base.load_resource(
        'replaymobile-img-licit', 'database', preferred_package='bob.bio.face')
204
205
    try:
        check_database(database, groups=('dev', 'eval'))
206
207
208
    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)
209
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
210
211
        _check_annotations(database, topleft=True, limit_files=20)
    except IOError as e:
212
213
        raise SkipTest(
            "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
214
215
216


@db_available('replaymobile')
Amir Mohammadi's avatar
Amir Mohammadi committed
217
def test_replaymobile_spoof():
218
219
    database = bob.bio.base.load_resource(
        'replaymobile-img-spoof', 'database', preferred_package='bob.bio.face')
220
221
222
223
224
    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)
225
    try:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
226
227
        _check_annotations(database, topleft=True, limit_files=20)
    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)
230
231
232
233
234
235
236
237
238
239
240
241
242


@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:
243
        _check_annotations(database, topleft=False, limit_files=20)
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    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:
261
        _check_annotations(database, topleft=False, limit_files=20)
262
263
264
265
    except IOError as e:
        raise SkipTest(
            "The annotations could not be queried; probably the annotation "
            "files are missing. Here is the error: '%s'" % e)
266
267
268
269
270
            

@db_available('ijbc')
def test_ijbc():
    database = bob.bio.base.load_resource(
271
        'ijbc-11', 'database', preferred_package='bob.bio.face')
272
273
274
275
276
277
278
279
280
281
282
    try:
        check_database(database, models_depend=True, training_depends=True)
    except IOError as e:
        raise SkipTest(
            "The database could not queried; Here is the error: '%s'" % e)
    try:
        _check_annotations(database, topleft=True, 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)

283
284
285
286
287
288
289
290
291
@db_available('fargo')
def test_fargo():
    database = bob.bio.base.load_resource(
        'fargo', 'database', preferred_package='bob.bio.face')
    try:
        check_database(database)
    except IOError as e:
        raise SkipTest(
            "The database could not queried; Here is the error: '%s'" % e)