diff --git a/bob/bio/face/database/__init__.py b/bob/bio/face/database/__init__.py index 6f9f5196e72021ebb41919284586011e423c32b6..3a0141b8dc1a342d665e6c6fc0e049bdad51424c 100644 --- a/bob/bio/face/database/__init__.py +++ b/bob/bio/face/database/__init__.py @@ -20,6 +20,7 @@ from .pola_thermal import PolaThermalDatabase from .cbsr_nir_vis_2 import CBSRNirVis2Database from .rfw import RFWDatabase from .scface import SCFaceDatabase +from .caspeal import CaspealDatabase # gets sphinx autodoc done right - don't remove it @@ -58,5 +59,6 @@ __appropriate__( FRGCDatabase, RFWDatabase, SCFaceDatabase, + CaspealDatabase, ) __all__ = [_ for _ in dir() if not _.startswith("_")] diff --git a/bob/bio/face/database/caspeal.py b/bob/bio/face/database/caspeal.py new file mode 100644 index 0000000000000000000000000000000000000000..d7f58c3c2f190053555f8517b3b5f22fe70203f5 --- /dev/null +++ b/bob/bio/face/database/caspeal.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : +# Tiago de Freitas Pereira + +""" + Multipie database implementation +""" + +from bob.bio.base.database import CSVDataset +from bob.bio.base.database import CSVToSampleLoaderBiometrics +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 + + +class CaspealDatabase(CSVDataset): + """ + The CAS-PEAL database consists of several ten thousand images of Chinese people (CAS = Chinese Academy of Science). + Overall, there are 1040 identities contained in the database. + For these identities, images with different Pose, Expression, Aging and Lighting (PEAL) conditions, as well as accessories, image backgrounds and camera distances are provided. + + Included in the database, there are file lists defining identification experiments. + All the experiments rely on a gallery that consists of the frontal and frontally illuminated images with neutral expression and no accessories. + For each of the variations, probe sets including exactly that variation are available. + + The training set consists of a subset of the frontal images (some images are both in the training and in the development set). + This also means that there is no training set defined for the pose images. + Additionally, the database defines only a development set, but no evaluation set. + + This package only contains the Bob_ accessor methods to use the DB directly from python, with our certified protocols. + We have implemented the default face identification protocols ``'accessory'``, ``'aging'``, ``'background'``, ``'distance'``, ``'expression'`` and ``'lighting'``. + We do not provide the ``'pose'`` protocol (yet) since the training set of the `CAS-PEAL `_ + database does not contain pose images: + + + .. code-block:: latex + + @article{gao2007cas, + title={The CAS-PEAL large-scale Chinese face database and baseline evaluations}, + author={Gao, Wen and Cao, Bo and Shan, Shiguang and Chen, Xilin and Zhou, Delong and Zhang, Xiaohua and Zhao, Debin}, + journal={IEEE Transactions on Systems, Man, and Cybernetics-Part A: Systems and Humans}, + volume={38}, + number={1}, + pages={149--161}, + year={2007}, + publisher={IEEE} + } + + """ + + def __init__(self, protocol, annotation_type="eyes-center", fixed_positions=None): + + # Downloading model if not exists + urls = CaspealDatabase.urls() + filename = get_file( + "caspeal-f2479a0b.tar.gz", + urls, + file_hash="c747f2810f5373e556c43f979b00dd06", + ) + + super().__init__( + name="caspeal", + dataset_protocol_path=filename, + protocol=protocol, + csv_to_sample_loader=make_pipeline( + CSVToSampleLoaderBiometrics( + data_loader=bob.io.base.load, + dataset_original_directory=rc["bob.bio.face.caspeal.directory"] + if rc["bob.bio.face.caspeal.directory"] + else "", + extension=".png", + ), + EyesAnnotations(), + ), + annotation_type="eyes-center", + fixed_positions=None, + ) + + @staticmethod + def protocols(): + # TODO: Until we have (if we have) a function that dumps the protocols, let's use this one. + protocols = [ + "accessory", + "aging", + "background", + "distance", + "expression", + "lighting", + ] + + @staticmethod + def urls(): + return [ + "https://www.idiap.ch/software/bob/databases/latest/caspeal-f2479a0b.tar.gz", + "http://www.idiap.ch/software/bob/databases/latest/caspeal-f2479a0b.tar.gz", + ] diff --git a/bob/bio/face/test/test_databases.py b/bob/bio/face/test/test_databases.py index c4d488cd27a7fa3c566c06d695415c65118dc44a..65fbe9c147f0e4bb0266d81a52d3d6e8d51c760b 100644 --- a/bob/bio/face/test/test_databases.py +++ b/bob/bio/face/test/test_databases.py @@ -98,29 +98,6 @@ def test_atnt(): ) -@db_available("gbu") -def test_gbu(): - database = bob.bio.base.load_resource( - "gbu", "database", preferred_package="bob.bio.face" - ) - try: - check_database(database, models_depend=True) - check_database(database, protocol="Bad", models_depend=True) - check_database(database, protocol="Ugly", models_depend=True) - except IOError as e: - pytest.skip( - "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" - % e - ) - try: - _check_annotations(database, limit_files=1000) - except IOError as e: - pytest.skip( - "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" - % e - ) - - @db_available("lfw") def test_lfw(): database = bob.bio.base.load_resource( @@ -574,3 +551,43 @@ def test_gbu(): assert len(database.probes()) == 1085 assert len(database.background_model_samples()) == 3910 + + +def test_caspeal(): + + from bob.bio.face.database import CaspealDatabase + + # protocols = ['accessory', 'aging', 'background', 'distance', 'expression', 'lighting', 'pose'] + + database = CaspealDatabase("accessory") + assert len(database.references()) == 1040 + assert len(database.probes()) == 2285 + assert len(database.background_model_samples()) == 1200 + + database = CaspealDatabase("aging") + assert len(database.references()) == 1040 + assert len(database.probes()) == 66 + assert len(database.background_model_samples()) == 1200 + + database = CaspealDatabase("background") + assert len(database.references()) == 1040 + assert len(database.probes()) == 553 + assert len(database.background_model_samples()) == 1200 + + database = CaspealDatabase("distance") + assert len(database.references()) == 1040 + assert len(database.probes()) == 275 + assert len(database.background_model_samples()) == 1200 + + database = CaspealDatabase("expression") + assert len(database.references()) == 1040 + assert len(database.probes()) == 1570 + assert len(database.background_model_samples()) == 1200 + + database = CaspealDatabase("lighting") + assert len(database.references()) == 1040 + assert len(database.probes()) == 2243 + assert len(database.background_model_samples()) == 1200 + + ### There's no pose protocol + diff --git a/doc/implemented.rst b/doc/implemented.rst index 4fe5ffea1f208017c1a265a5d9390f5e2a7471cd..a8cb9a4c1e044efa2bfb044f13a54dec0950e029 100644 --- a/doc/implemented.rst +++ b/doc/implemented.rst @@ -26,6 +26,7 @@ Databases bob.bio.face.database.PolaThermalDatabase bob.bio.face.database.CBSRNirVis2Database bob.bio.face.database.SCFaceDatabase + bob.bio.face.database.CaspealDatabase Deep Learning Extractors