Skip to content
Snippets Groups Projects
Commit aead0f0a authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Make the original_directory and annotation_directory a property

parent a0b12ee9
No related branches found
No related tags found
1 merge request!36Make the original_directory and annotation_directory a property
Pipeline #
Showing with 220 additions and 89 deletions
......@@ -33,6 +33,9 @@ class ARFaceBioDatabase(BioDatabase):
original_extension='.ppm',
**kwargs
):
from bob.db.arface.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(ARFaceBioDatabase, self).__init__(
name='arface',
......@@ -40,8 +43,13 @@ class ARFaceBioDatabase(BioDatabase):
original_extension=original_extension,
**kwargs)
from bob.db.arface.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -33,6 +33,9 @@ class BancaBioDatabase(ZTBioDatabase):
original_extension=None,
**kwargs
):
from bob.db.banca.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(BancaBioDatabase, self).__init__(
name='banca',
......@@ -40,8 +43,13 @@ class BancaBioDatabase(ZTBioDatabase):
original_extension=original_extension,
**kwargs)
from bob.db.banca.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -33,6 +33,9 @@ class CaspealBioDatabase(BioDatabase):
original_extension='.tif',
**kwargs
):
from bob.db.caspeal.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(CaspealBioDatabase, self).__init__(
name='caspeal',
......@@ -40,8 +43,13 @@ class CaspealBioDatabase(BioDatabase):
original_extension=original_extension,
**kwargs)
from bob.db.caspeal.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -34,6 +34,9 @@ class FRGCBioDatabase(BioDatabase):
original_extension='.jpg',
**kwargs
):
from bob.db.frgc.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(FRGCBioDatabase, self).__init__(
name='frgc',
......@@ -41,8 +44,13 @@ class FRGCBioDatabase(BioDatabase):
original_extension=original_extension,
**kwargs)
from bob.db.frgc.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -33,6 +33,9 @@ class GBUBioDatabase(BioDatabase):
original_extension='.jpg',
**kwargs
):
from bob.db.gbu.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(GBUBioDatabase, self).__init__(
name='GBU',
......@@ -40,8 +43,13 @@ class GBUBioDatabase(BioDatabase):
original_extension=original_extension,
**kwargs)
from bob.db.gbu.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -16,73 +16,92 @@ import bob.io.image
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):
super(IJBABioFile, self).__init__(
client_id=f.client_id, path=f.path, file_id=f.id)
self.f = f
def load(self, directory, extension=None, add_client_id=False):
return bob.io.image.load(self.make_path(directory, self.f.extension, add_client_id))
def load(self, directory, extension=None, add_client_id=False):
return bob.io.image.load(self.make_path(directory, self.f.extension, add_client_id))
def make_path(self, directory, extension, add_client_id=True):
if add_client_id:
# add client ID to the path, so that a unique path is generated
# (there might be several identities in each physical file)
path = "%s-%s%s" % (self.path, self.client_id, extension or '')
else:
# do not add the client ID to be able to obtain the original image file
path = "%s%s" % (self.path, extension or '')
return str(os.path.join(directory or '', path))
def make_path(self, directory, extension, add_client_id=True):
if add_client_id:
# add client ID to the path, so that a unique path is generated
# (there might be several identities in each physical file)
path = "%s-%s%s" % (self.path, self.client_id, extension or '')
else:
# do not add the client ID to be able to obtain the original image file
path = "%s%s" % (self.path, extension or '')
return str(os.path.join(directory or '', path))
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)
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):
"""
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
verification experiments (good to use in bob.bio.base framework).
"""
def __init__(
self,
original_directory=None,
annotations_directory=None,
original_extension=None,
**kwargs
):
# call base class constructors to open a session to the database
super(IJBABioDatabase, self).__init__(
"""
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
verification experiments (good to use in bob.bio.base framework).
"""
def __init__(
self,
original_directory=None,
annotation_directory=None,
original_extension=None,
**kwargs
):
from bob.db.ijba.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(
original_directory, annotation_directory, original_extension)
# call base class constructors to open a session to the database
super(IJBABioDatabase, self).__init__(
name='ijba',
models_depend_on_protocol=True,
training_depends_on_protocol=True,
original_directory=original_directory,
annotations_directory=annotations_directory,
annotation_directory=annotation_directory,
original_extension=original_extension,
**kwargs)
from bob.db.ijba.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, annotations_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
def uses_probe_file_sets(self):
return True
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol="search_split1", **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
@property
def annotation_directory(self):
return self._db.annotation_directory
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)]
@annotation_directory.setter
def annotation_directory(self, value):
self._db.annotation_directory = value
def object_sets(self, groups=None, protocol="search_split1", purposes=None, model_ids=None):
return [IJBABioFileSet(t) for t in self._db.object_sets(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids)]
def uses_probe_file_sets(self):
return True
def annotations(self, biofile):
return self._db.annotations(biofile.f)
def model_ids_with_protocol(self, groups=None, protocol="search_split1", **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
def client_id_from_model_id(self, model_id, group='dev'):
return self._db.get_client_id_from_model_id(model_id)
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 original_file_names(self, files):
return [f.make_path(self.original_directory, f.f.extension, False) for f in files]
def object_sets(self, groups=None, protocol="search_split1", purposes=None, model_ids=None):
return [IJBABioFileSet(t) for t in self._db.object_sets(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids)]
def annotations(self, biofile):
return self._db.annotations(biofile.f)
def client_id_from_model_id(self, model_id, group='dev'):
return self._db.get_client_id_from_model_id(model_id)
def original_file_names(self, files):
return [f.make_path(self.original_directory, f.f.extension, False) for f in files]
......@@ -35,6 +35,9 @@ class LFWBioDatabase(BioDatabase):
annotation_type=None,
**kwargs
):
from bob.db.lfw.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension, annotation_type)
# call base class constructors to open a session to the database
super(LFWBioDatabase, self).__init__(
name='lfw',
......@@ -43,8 +46,13 @@ class LFWBioDatabase(BioDatabase):
annotation_type=annotation_type,
**kwargs)
from bob.db.lfw.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension, annotation_type)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......@@ -55,13 +63,13 @@ class LFWBioDatabase(BioDatabase):
def annotations(self, myfile):
return self._db.annotations(myfile._f)
def client_id_from_model_id(self, model_id, group='dev'):
"""Return the client id associated with the given model id.
In this base class implementation, it is assumed that only one model is enrolled for each client and, thus, client id and model id are identical.
All key word arguments are ignored.
Please override this function in derived class implementations to change this behavior."""
# since there is one model per file, we can re-use the function above.
return self._db.get_client_id_from_file_id(model_id)
return self._db.get_client_id_from_file_id(model_id)
......@@ -37,6 +37,10 @@ class MobioBioDatabase(ZTBioDatabase):
annotation_extension='.pos',
**kwargs
):
from bob.db.mobio.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension,
annotation_directory, annotation_extension)
# call base class constructors to open a session to the database
super(MobioBioDatabase, self).__init__(
name='mobio',
......@@ -46,9 +50,21 @@ class MobioBioDatabase(ZTBioDatabase):
annotation_extension=annotation_extension,
**kwargs)
from bob.db.mobio.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension,
annotation_directory, annotation_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
@property
def annotation_directory(self):
return self._db.annotation_directory
@annotation_directory.setter
def annotation_directory(self, value):
self._db.annotation_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, gender=None):
return self._db.model_ids(groups=groups, protocol=protocol, gender=gender)
......
......@@ -32,15 +32,23 @@ class MsuMfsdModBioDatabase(BioDatabase):
"""
def __init__(self, max_number_of_frames=None, **kwargs):
# call base class constructors to open a session to the database
super(MsuMfsdModBioDatabase, self).__init__(
name='msu-mfsd-mod',
max_number_of_frames=max_number_of_frames, **kwargs)
from bob.db.msu_mfsd_mod.verificationprotocol import Database \
as LowLevelDatabase
self._db = LowLevelDatabase(max_number_of_frames)
# call base class constructors to open a session to the database
super(MsuMfsdModBioDatabase, self).__init__(
name='msu-mfsd-mod', **kwargs)
self._kwargs['max_number_of_frames'] = max_number_of_frames
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def protocol_names(self):
return self._db.protocols()
......
......@@ -35,6 +35,12 @@ class MultipieBioDatabase(ZTBioDatabase):
annotation_extension='.pos',
**kwargs
):
from bob.db.multipie.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory,
original_extension,
annotation_directory,
annotation_extension)
# call base class constructors to open a session to the database
super(MultipieBioDatabase, self).__init__(
name='multipie',
......@@ -44,11 +50,13 @@ class MultipieBioDatabase(ZTBioDatabase):
annotation_extension=annotation_extension,
**kwargs)
from bob.db.multipie.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory,
original_extension,
annotation_directory,
annotation_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -37,15 +37,23 @@ class ReplayBioDatabase(BioDatabase):
__doc__ = __doc__
def __init__(self, **kwargs):
# call base class constructors to open a session to the database
super(ReplayBioDatabase, self).__init__(name='replay', **kwargs)
from bob.db.replay import Database as LowLevelDatabase
self._db = LowLevelDatabase()
# call base class constructors to open a session to the database
super(ReplayBioDatabase, self).__init__(name='replay', **kwargs)
self.low_level_group_names = ('train', 'devel', 'test')
self.high_level_group_names = ('world', 'dev', 'eval')
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def protocol_names(self):
"""Returns all registered protocol names
Here I am going to hack and double the number of protocols
......
......@@ -30,13 +30,21 @@ class ReplayMobileBioDatabase(BioDatabase):
"""
def __init__(self, max_number_of_frames=None, **kwargs):
from bob.db.replaymobile.verificationprotocol import Database as LowLevelDatabase
self._db = LowLevelDatabase(max_number_of_frames)
# call base class constructors to open a session to the database
super(ReplayMobileBioDatabase, self).__init__(
name='replay-mobile',
max_number_of_frames=max_number_of_frames, **kwargs)
name='replay-mobile', **kwargs)
self._kwargs['max_number_of_frames'] = max_number_of_frames
from bob.db.replaymobile.verificationprotocol import Database as LowLevelDatabase
self._db = LowLevelDatabase(max_number_of_frames)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def protocol_names(self):
return self._db.protocols()
......
......@@ -33,6 +33,9 @@ class SCFaceBioDatabase(ZTBioDatabase):
original_extension='.jpg',
**kwargs
):
from bob.db.scface.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(SCFaceBioDatabase, self).__init__(
name='scface',
......@@ -40,8 +43,13 @@ class SCFaceBioDatabase(ZTBioDatabase):
original_extension=original_extension,
**kwargs)
from bob.db.scface.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -33,6 +33,9 @@ class XM2VTSBioDatabase(BioDatabase):
original_extension='.ppm',
**kwargs
):
from bob.db.xm2vts.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(XM2VTSBioDatabase, self).__init__(
name='xm2vts',
......@@ -40,8 +43,13 @@ class XM2VTSBioDatabase(BioDatabase):
original_extension=original_extension,
**kwargs)
from bob.db.xm2vts.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
......
......@@ -334,7 +334,7 @@ def test_msu_mfsd_mod_licit():
"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)
_check_annotations(database, topleft=False, limit_files=20)
except IOError as e:
raise SkipTest(
"The annotations could not be queried; probably the annotation "
......@@ -352,7 +352,7 @@ def test_msu_mfsd_mod_spoof():
"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)
_check_annotations(database, topleft=False, limit_files=20)
except IOError as e:
raise SkipTest(
"The annotations could not be queried; probably the annotation "
......
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