Skip to content
Snippets Groups Projects
Commit 8190e864 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Merge branch 'issue-8-remove-database-configuration' into 'master'

Issue 8 remove database configuration

Solving issue #37  (some database tests are missing)


See merge request !38
parents 554419d6 e7722c0c
No related branches found
No related tags found
1 merge request!38Issue 8 remove database configuration
Pipeline #
...@@ -22,7 +22,7 @@ class Preprocessor: ...@@ -22,7 +22,7 @@ class Preprocessor:
A list of keyword arguments to be written in the :py:meth:`__str__` function. 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 # Each class needs to have a constructor taking
# all the parameters that are required for the preprocessing as arguments # all the parameters that are required for the preprocessing as arguments
self.writes_data = writes_data self.writes_data = writes_data
......
#!/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
...@@ -4,6 +4,7 @@ import tempfile, tarfile ...@@ -4,6 +4,7 @@ import tempfile, tarfile
import logging import logging
logger = logging.getLogger("bob.bio.base") logger = logging.getLogger("bob.bio.base")
from .. import database
import bob.io.base import bob.io.base
def filter_missing_files(file_names, split_by_client=False, allow_missing_files=True): 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): ...@@ -51,6 +52,33 @@ def check_file(filename, force, expected_file_size = 1):
return False 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): def load(file):
"""Loads data from file. The given file might be an HDF5 file open for reading or a string.""" """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): if isinstance(file, bob.io.base.HDF5File):
......
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