diff --git a/bob/bio/base/preprocessor/Preprocessor.py b/bob/bio/base/preprocessor/Preprocessor.py index ba9e4fcd5be34e13e3565afb67c4df58b97fce4c..6c61cabd18c5831afae1757a1ca0c1015c23d12a 100644 --- a/bob/bio/base/preprocessor/Preprocessor.py +++ b/bob/bio/base/preprocessor/Preprocessor.py @@ -22,7 +22,7 @@ class Preprocessor: A list of keyword arguments to be written in the :py:meth:`__str__` function. """ - def __init__(self, writes_data = True, read_original_data = lambda biofile,directory,extension : biofile.load(directory,extension), **kwargs): + def __init__(self, writes_data = True, read_original_data = utils.read_original_data, **kwargs): # Each class needs to have a constructor taking # all the parameters that are required for the preprocessing as arguments self.writes_data = writes_data diff --git a/bob/bio/base/test/test_database_implementations.py b/bob/bio/base/test/test_database_implementations.py new file mode 100644 index 0000000000000000000000000000000000000000..de0d02ed3f39e7989d1d5f51125600f48efc6b53 --- /dev/null +++ b/bob/bio/base/test/test_database_implementations.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : +# Amir Mohammadi <amir.mohammadi@idiap.ch> +# Wed 20 July 16:20:12 CEST 2016 +# + +""" +Very simple tests for Implementations +""" + +import os +from bob.bio.base.database import BioDatabase, ZTBioDatabase + + +def check_database(database, groups=('dev',), protocol=None, training_depends=False, models_depend=False): + assert isinstance(database, BioDatabase) + + # load the directories + if 'HOME' in os.environ: + database.replace_directories(os.path.join(os.environ['HOME'], '.bob_bio_databases.txt')) + + if protocol: database.protocol = protocol + if protocol is None: protocol = database.protocol + + assert len(database.all_files()) > 0 + assert len(database.training_files('train_extractor')) > 0 + assert len(database.arrange_by_client(database.training_files('train_enroller'))) > 0 + + for group in groups: + model_ids = database.model_ids_with_protocol(group, protocol=protocol) + assert len(model_ids) > 0 + assert database.client_id_from_model_id(model_ids[0]) is not None + assert len(database.enroll_files(model_ids[0], group)) > 0 + assert len(database.probe_files(model_ids[0], group)) > 0 + + assert database.training_depends_on_protocol == training_depends + assert database.models_depend_on_protocol == models_depend + + +def check_database_zt(database, groups=('dev', 'eval'), protocol=None, training_depends=False, models_depend=False): + check_database(database, groups, protocol, training_depends, models_depend) + assert isinstance(database, ZTBioDatabase) + for group in groups: + t_model_ids = database.t_model_ids(group) + assert len(t_model_ids) > 0 + assert database.client_id_from_model_id(t_model_ids[0]) is not None + assert len(database.t_enroll_files(t_model_ids[0], group)) > 0 + assert len(database.z_probe_files(group)) > 0 + + diff --git a/bob/bio/base/utils/io.py b/bob/bio/base/utils/io.py index 1e73f499437ef64a82c493128f7596b8c0ad7cca..3e25a5255fcd40b32e9b781ef86a4b8e3ab66802 100644 --- a/bob/bio/base/utils/io.py +++ b/bob/bio/base/utils/io.py @@ -4,6 +4,7 @@ import tempfile, tarfile import logging logger = logging.getLogger("bob.bio.base") +from .. import database import bob.io.base def filter_missing_files(file_names, split_by_client=False, allow_missing_files=True): @@ -51,6 +52,33 @@ def check_file(filename, force, expected_file_size = 1): return False +def read_original_data(biofile, directory, extension): + """read_original_data(biofile, directory, extension) -> data + + This function reads the original data using the given ``biofile`` instance. + It simply calls ``load(directory, extension)`` from :py:class:`bob.bio.base.database.BioFile` or one of its derivatives. + + **Parameters:** + + ``biofile`` : :py:class:`bob.bio.base.database.BioFile` or one of its derivatives + The file to read the original data. + + ``directory`` : str + The base directory of the database. + + ``extension`` : str or ``None`` + The extension of the original data. + Might be ``None`` if the ``biofile`` itself has the extension stored. + + **Returns** + + ``data`` : object + Whatver ``biofile.load`` returns; usually a :py:class:`numpy.ndarray` + """ + assert isinstance(biofile, database.BioFile) + return biofile.load(directory, extension) + + def load(file): """Loads data from file. The given file might be an HDF5 file open for reading or a string.""" if isinstance(file, bob.io.base.HDF5File):