diff --git a/bob/bio/face/config/database/mobio.py b/bob/bio/face/config/database/mobio.py deleted file mode 100644 index c2f40b0d9b286415424d766735443acc10d7979b..0000000000000000000000000000000000000000 --- a/bob/bio/face/config/database/mobio.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python - -from bob.bio.face.database import MobioBioDatabase -from bob.bio.base.pipelines.vanilla_biometrics import DatabaseConnector -from bob.extension import rc - -database = DatabaseConnector( - MobioBioDatabase( - original_directory=rc["bob.db.mobio.directory"], - annotation_directory=rc["bob.db.mobio.annotation_directory"], - original_extension=".png", - protocol="mobile0-male", - ) -) -database.allow_scoring_with_all_biometric_references = True - - -mobio_image_directory = rc["bob.db.mobio.directory"] -mobio_annotation_directory = rc["bob.db.mobio.annotation_directory"] - -allow_scoring_with_all_biometric_references = True -annotation_type = "eyes-center" -fixed_positions = None - - -mobio_image = DatabaseConnector( - MobioBioDatabase( - original_directory=mobio_image_directory, - original_extension=".png", - annotation_directory=mobio_annotation_directory, - annotation_type="eyecenter", - protocol="male", - models_depend_on_protocol=True, - ), - allow_scoring_with_all_biometric_references=allow_scoring_with_all_biometric_references, - annotation_type=annotation_type, - fixed_positions=fixed_positions, -) - - -mobio_male = DatabaseConnector( - MobioBioDatabase( - original_directory=mobio_image_directory, - original_extension=".png", - annotation_directory=mobio_annotation_directory, - annotation_type="eyecenter", - protocol="male", - models_depend_on_protocol=True, - all_files_options={"gender": "male"}, - extractor_training_options={"gender": "male"}, - projector_training_options={"gender": "male"}, - enroller_training_options={"gender": "male"}, - z_probe_options={"gender": "male"}, - ), - allow_scoring_with_all_biometric_references=allow_scoring_with_all_biometric_references, - annotation_type=annotation_type, - fixed_positions=fixed_positions, -) - - -mobio_female = DatabaseConnector( - MobioBioDatabase( - original_directory=mobio_image_directory, - original_extension=".png", - annotation_directory=mobio_annotation_directory, - annotation_type="eyecenter", - protocol="female", - models_depend_on_protocol=True, - all_files_options={"gender": "female"}, - extractor_training_options={"gender": "female"}, - projector_training_options={"gender": "female"}, - enroller_training_options={"gender": "female"}, - z_probe_options={"gender": "female"}, - ), - allow_scoring_with_all_biometric_references=allow_scoring_with_all_biometric_references, - annotation_type=annotation_type, - fixed_positions=fixed_positions, -) diff --git a/bob/bio/face/config/database/mobio_all.py b/bob/bio/face/config/database/mobio_all.py index 8492d8cb54eb3b20b568133803f379deb7e4372b..bb2d0c0c1be80cec28913848fb520eaa4586cd77 100644 --- a/bob/bio/face/config/database/mobio_all.py +++ b/bob/bio/face/config/database/mobio_all.py @@ -1,17 +1,5 @@ #!/usr/bin/env python -from bob.bio.face.database import MobioBioDatabase -from bob.bio.base.pipelines.vanilla_biometrics import DatabaseConnector -from bob.extension import rc - -database = DatabaseConnector( - MobioBioDatabase( - original_directory=rc["bob.db.mobio.directory"], - annotation_directory=rc["bob.db.mobio.annotation_directory"], - original_extension=".png", - protocol="mobile0-male-female", - ), - annotation_type = "eyes-center", - fixed_positions = None -) +from bob.bio.face.database import MobioDatabase +database = MobioDatabase(protocol="mobile0-male-female") diff --git a/bob/bio/face/config/database/mobio_male.py b/bob/bio/face/config/database/mobio_male.py index b33f356031fc28d93ab79d76671f4d712ad379af..49a4da62497678448354e81e1c0ed2d8ef460f31 100644 --- a/bob/bio/face/config/database/mobio_male.py +++ b/bob/bio/face/config/database/mobio_male.py @@ -1,17 +1,5 @@ #!/usr/bin/env python -from bob.bio.face.database import MobioBioDatabase -from bob.bio.base.pipelines.vanilla_biometrics import DatabaseConnector -from bob.extension import rc - -database = DatabaseConnector( - MobioBioDatabase( - original_directory=rc["bob.db.mobio.directory"], - annotation_directory=rc["bob.db.mobio.annotation_directory"], - original_extension=".png", - protocol="mobile0-male", - ), - annotation_type = "eyes-center", - fixed_positions = None -) +from bob.bio.face.database import MobioDatabase +database = MobioDatabase(protocol="mobile0-male") diff --git a/bob/bio/face/database/__init__.py b/bob/bio/face/database/__init__.py index 3c0429f2e189eaacd4280f9ee99cdf78e3da237f..c5a067f6d790b15d609c3aea7a5aa8a695430944 100644 --- a/bob/bio/face/database/__init__.py +++ b/bob/bio/face/database/__init__.py @@ -2,7 +2,7 @@ # vim: set fileencoding=utf-8 : from .database import FaceBioFile -from .mobio import MobioBioDatabase +from .mobio import MobioDatabase from .replay import ReplayBioDatabase from .atnt import AtntBioDatabase from .gbu import GBUBioDatabase @@ -35,7 +35,7 @@ def __appropriate__(*args): __appropriate__( FaceBioFile, - MobioBioDatabase, + MobioDatabase, ReplayBioDatabase, AtntBioDatabase, GBUBioDatabase, diff --git a/bob/bio/face/database/mobio.py b/bob/bio/face/database/mobio.py index f09b4fe49ff8da219cf449513944793de97a2d29..839ad3174ceb876669eade1e827c4c119d12d9bc 100644 --- a/bob/bio/face/database/mobio.py +++ b/bob/bio/face/database/mobio.py @@ -1,92 +1,96 @@ #!/usr/bin/env python # vim: set fileencoding=utf-8 : -# Amir Mohammadi <amir.mohammadi@idiap.ch> -# Wed 13 Jul 16:43:22 CEST 2016 +# Tiago de Freitas Pereira <tiago.pereira@idiap.ch> """ - MOBIO database implementation of bob.bio.base.database.ZTBioDatabase interface. - It is an extension of an SQL-based database interface, which directly talks to Mobio database, for - verification experiments (good to use in bob.bio.base framework). + MOBIO database implementation """ +from bob.bio.base.database import ( + CSVDataset, + CSVDatasetZTNorm, +) +from bob.pipelines.datasets import CSVToSampleLoader +from bob.bio.face.database.sample_loaders import EyesAnnotations +from bob.extension import rc +from bob.extension.download import get_file +import bob.io.base +from sklearn.pipeline import make_pipeline -from .database import FaceBioFile -from bob.bio.base.database import ZTBioDatabase - -class MobioBioFile(FaceBioFile): - """FaceBioFile implementation of the Mobio Database""" - - def __init__(self, f): - super(MobioBioFile, self).__init__(client_id=f.client_id, path=f.path, file_id=f.id) - self._f = f - - -class MobioBioDatabase(ZTBioDatabase): - """ - MOBIO database implementation of bob.bio.base.database.ZTBioDatabase interface. - It is an extension of an SQL-based database interface, which directly talks to Mobio database, for - verification experiments (good to use in bob.bio.base framework). +class MobioDatabase(CSVDatasetZTNorm): """ + The MOBIO dataset is a video database containing bimodal data (face/speaker). + It is composed by 152 people (split in the two genders male and female), mostly Europeans, split in 5 sessions (few weeks time lapse between sessions). + The database was recorded using two types of mobile devices: mobile phones (NOKIA N93i) and laptop + computers(standard 2008 MacBook). + + For face recognition images are used instead of videos. + One image was extracted from each video by choosing the video frame after 10 seconds. + The eye positions were manually labelled and distributed with the database. + + For more information check: + + .. code-block:: latex + + @article{McCool_IET_BMT_2013, + title = {Session variability modelling for face authentication}, + author = {McCool, Chris and Wallace, Roy and McLaren, Mitchell and El Shafey, Laurent and Marcel, S{\'{e}}bastien}, + month = sep, + journal = {IET Biometrics}, + volume = {2}, + number = {3}, + year = {2013}, + pages = {117-129}, + issn = {2047-4938}, + doi = {10.1049/iet-bmt.2012.0059}, + } - def __init__( - self, - original_directory=None, - original_extension=None, - annotation_directory=None, - 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', - original_directory=original_directory, - original_extension=original_extension, - annotation_directory=annotation_directory, - annotation_extension=annotation_extension, - **kwargs) - - @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) - - def tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs): - return self._db.tmodel_ids(protocol=protocol, groups=groups, **kwargs) - - def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs): - retval = self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs) - return [MobioBioFile(f) for f in retval] - - def tobjects(self, groups=None, protocol=None, model_ids=None, **kwargs): - retval = self._db.tobjects(groups=groups, protocol=protocol, model_ids=model_ids, **kwargs) - return [MobioBioFile(f) for f in retval] - - def zobjects(self, groups=None, protocol=None, **kwargs): - retval = self._db.zobjects(groups=groups, protocol=protocol, **kwargs) - return [MobioBioFile(f) for f in retval] - - def annotations(self, myfile): - return self._db.annotations(myfile._f) - - def groups(self, protocol=None, **kwargs): - return self._db.groups(protocol=protocol) + """ + def __init__(self, protocol): + + # Downloading model if not exists + urls = [ + "https://www.idiap.ch/software/bob/databases/latest/mobio.tar.gz", + "http://www.idiap.ch/software/bob/databases/latest/mobio.tar.gz", + ] + filename = get_file("mobio.tar.gz", urls) + + self.annotation_type = "eyes-center" + self.fixed_positions = None + + database = CSVDataset( + filename, + protocol, + csv_to_sample_loader=make_pipeline( + CSVToSampleLoader( + data_loader=bob.io.base.load, + dataset_original_directory=rc["bob.db.mobio.directory"] + if rc["bob.db.mobio.directory"] + else "", + extension=".png", + ), + EyesAnnotations(), + ), + ) + + super().__init__(database) + + # def zprobes(self, proportion=0.20): + # return super().zprobes(proportion=proportion) + + @staticmethod + def protocols(): + # TODO: Until we have (if we have) a function that dumps the protocols, let's use this one. + return [ + "laptop1-female", + "laptop_mobile1-female", + "mobile0-female", + "mobile0-male-female", + "mobile1-male", + "laptop1-male", + "laptop_mobile1-male", + "mobile0-male", + "mobile1-female", + ] diff --git a/bob/bio/face/test/test_databases.py b/bob/bio/face/test/test_databases.py index 856ac9f0134d224bb6151915f30501ed49d3f6d9..36003bafc1fe4accfe1ab4f5bd78da5d93ba70b1 100644 --- a/bob/bio/face/test/test_databases.py +++ b/bob/bio/face/test/test_databases.py @@ -156,39 +156,34 @@ def test_lfw(): ) -@db_available("mobio") def test_mobio(): - database = bob.bio.base.load_resource( - "mobio-image", "database", preferred_package="bob.bio.face" - ) - try: - 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, - ) - 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 - ) + from bob.bio.face.database import MobioDatabase - 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 - ) + protocols = MobioDatabase.protocols() + for p in protocols: + database = MobioDatabase(protocol=p) + assert len(database.background_model_samples()) > 0 + assert len(database.treferences()) > 0 + assert len(database.zprobes()) > 0 + + assert len(database.references(group="dev")) > 0 + assert len(database.probes(group="dev")) > 0 + + assert len(database.references(group="eval")) > 0 + assert len(database.probes(group="eval")) > 0 + + # Sanity check on mobio-male + database = MobioDatabase(protocol="mobile0-male") + + assert len(database.treferences()) == 16 + assert len(database.zprobes()) == 1920 + assert len(database.background_model_samples()) == 9600 + + assert len(database.references()) == 24 + assert len(database.probes()) == 2520 + + assert len(database.references(group="eval")) == 38 + assert len(database.probes(group="eval")) == 3990 @db_available("multipie") diff --git a/conda/meta.yaml b/conda/meta.yaml index 88f4cb414d98950e6f5ed8e1d2dd504946793888..92163e39ccd36f2c88d782c5c9d023f57cbf9309 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -75,7 +75,6 @@ test: - bob.db.gbu - bob.db.ijbc - bob.db.lfw - - bob.db.mobio - bob.db.multipie - bob.db.replay - bob.db.replaymobile diff --git a/doc/implemented.rst b/doc/implemented.rst index 0deac2602496a6ed7390588ea7b7666459ef43d3..f9f67efc07c8499407dfb51924f146dc2441e430 100644 --- a/doc/implemented.rst +++ b/doc/implemented.rst @@ -13,7 +13,7 @@ Databases .. autosummary:: bob.bio.face.database.ARFaceBioDatabase bob.bio.face.database.AtntBioDatabase - bob.bio.face.database.MobioBioDatabase + bob.bio.face.database.MobioDatabase bob.bio.face.database.ReplayBioDatabase bob.bio.face.database.ReplayMobileBioDatabase bob.bio.face.database.GBUBioDatabase diff --git a/test-requirements.txt b/test-requirements.txt index d151d8fa1e53521dfd0dea36d9484920572b5a5b..c6be4dbbac8973d64e0e0f2724937c0409c73577 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,7 +4,6 @@ bob.db.banca bob.db.gbu bob.db.ijbc bob.db.lfw -bob.db.mobio bob.db.multipie bob.db.replay bob.db.replaymobile