Skip to content
Snippets Groups Projects
Commit 39fbe912 authored by Manuel Günther's avatar Manuel Günther
Browse files

Implemented IJBA database interface correctly

parent a080d605
No related branches found
No related tags found
1 merge request!25Resolve "IJB-A database implemented incorrectly"
#!/usr/bin/env python
from bob.bio.face.database import IJBABioDatabase
ijba_directory = "[YOUR_IJBA_DIRECTORY]"
database = IJBABioDatabase(
original_directory=ijba_directory,
protocol='search_split1'
)
...@@ -4,54 +4,72 @@ ...@@ -4,54 +4,72 @@
# Sat 20 Aug 15:43:10 CEST 2016 # Sat 20 Aug 15:43:10 CEST 2016
""" """
IJBA database implementation of bob.bio.base.database.Database interface. IJBA database implementation of bob.bio.base.database.BioDatabase interface.
It is an extension of an SQL-based database interface, which directly talks to IJBA database, for It is an extension of the database interface, which directly talks to IJBA database, for
verification experiments (good to use in bob.bio.base framework). verification experiments (good to use in bob.bio.base framework).
""" """
from .database import FaceBioFile from .database import FaceBioFile
from bob.bio.base.database import BioDatabase from bob.bio.base.database import BioDatabase, BioFileSet
import os
class IJBABioFile(FaceBioFile): class IJBABioFile(FaceBioFile):
def __init__(self, f):
super(IJBABioFile, self).__init__(client_id=f.client_id, path=f.path, file_id=f.id)
self.f = f
def __init__(self, f): def make_path(self, directory, extension):
super(IJBABioFile, self).__init__(client_id=f.client_id, path=f.path, file_id=f.id) # add file ID to the path, so that a unique path is generated (there might be several identities in each physical file)
self._f = f return str(os.path.join(directory or '', self.path + "-" + str(self.id) + (extension or '')))
class IJBABioFileSet(BioFileSet):
def __init__(self, template):
super(IJBABioFileSet, self).__init__(file_set_id = template.id, files = [IJBABioFile(f) for f in template.files], path = template.path)
class IJBABioDatabase(BioDatabase): class IJBABioDatabase(BioDatabase):
""" """
IJBA database implementation of :py:class:`bob.bio.base.database.BioDatabase` interface. IJBA database implementation of :py:class:`bob.bio.base.database.BioDatabase` interface.
It is an extension of an SQL-based database interface, which directly talks to IJBA database, for It is an extension of an SQL-based database interface, which directly talks to IJBA database, for
verification experiments (good to use in bob.bio.base framework). verification experiments (good to use in bob.bio.base framework).
""" """
def __init__( def __init__(
self, self,
original_directory=None, original_directory=None,
annotations_directory=None, annotations_directory=None,
original_extension=None, original_extension=None,
**kwargs **kwargs
): ):
# call base class constructors to open a session to the database # call base class constructors to open a session to the database
super(IJBABioDatabase, self).__init__( super(IJBABioDatabase, self).__init__(
models_depend_on_protocol=True,
training_depends_on_protocol=True,
name='ijba', name='ijba',
original_directory=original_directory, original_directory=original_directory,
annotations_directory=annotations_directory, annotations_directory=annotations_directory,
original_extension=original_extension, original_extension=original_extension,
**kwargs) **kwargs)
from bob.db.ijba.query import Database as LowLevelDatabase from bob.db.ijba.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, annotations_directory, self._db = LowLevelDatabase(original_directory, annotations_directory, original_extension)
original_extension)
def uses_probe_file_sets(self):
return True
def model_ids_with_protocol(self, groups=None, protocol="search_split1", **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
def objects(self, groups=None, protocol="search_split1", purposes=None, model_ids=None, **kwargs):
return [IJBABioFile(f) for f in self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)]
def model_ids_with_protocol(self, groups=None, protocol="search_split1", **kwargs): def object_sets(self, groups=None, protocol="search_split1", purposes=None, model_ids=None):
return self._db.model_ids(groups=groups, protocol=protocol) return [IJBABioFileSet(t) for t in self._db.object_sets(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids)]
def objects(self, groups=None, protocol="search_split1", purposes=None, model_ids=None, **kwargs): def annotations(self, biofile):
retval = self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs) return self._db.annotations(biofile.f)
return [IJBABioFile(f) for f in retval]
def annotations(self, myfile): def client_id_from_model_id(self, model_id, group='dev'):
return self._db.annotations(myfile._f) return self._db.get_client_id_from_model_id(model_id)
...@@ -165,12 +165,12 @@ def test_ijba(): ...@@ -165,12 +165,12 @@ def test_ijba():
database = bob.bio.base.load_resource( database = bob.bio.base.load_resource(
'ijba', 'database', preferred_package='bob.bio.face') 'ijba', 'database', preferred_package='bob.bio.face')
try: try:
check_database(database) check_database(database,models_depend=True, training_depends=True)
except IOError as e: except IOError as e:
raise SkipTest( raise SkipTest(
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e) "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
try: try:
_check_annotations(database, limit_files=1000) _check_annotations(database, topleft=True, limit_files=1000)
except IOError as e: except IOError as e:
raise SkipTest( raise SkipTest(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e) "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
......
...@@ -114,6 +114,7 @@ setup( ...@@ -114,6 +114,7 @@ setup(
'caspeal = bob.bio.face.config.database.caspeal:database', 'caspeal = bob.bio.face.config.database.caspeal:database',
'frgc = bob.bio.face.config.database.frgc:database', 'frgc = bob.bio.face.config.database.frgc:database',
'gbu = bob.bio.face.config.database.gbu:database', 'gbu = bob.bio.face.config.database.gbu:database',
'ijba = bob.bio.face.config.database.ijba:database',
'lfw-restricted = bob.bio.face.config.database.lfw_restricted:database', 'lfw-restricted = bob.bio.face.config.database.lfw_restricted:database',
'lfw-unrestricted = bob.bio.face.config.database.lfw_unrestricted:database', 'lfw-unrestricted = bob.bio.face.config.database.lfw_unrestricted:database',
'mobio-image = bob.bio.face.config.database.mobio:mobio_image', 'mobio-image = bob.bio.face.config.database.mobio:mobio_image',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment