Python API

bob.bio.db.get_config()[source]

Returns a string containing the configuration information.

class bob.bio.db.BioDatabase(name, all_files_options={}, extractor_training_options={}, projector_training_options={}, enroller_training_options={}, check_original_files_for_existence=False, original_directory=None, original_extension=None, annotation_directory=None, annotation_extension='.pos', annotation_type=None, protocol='Default', training_depends_on_protocol=False, models_depend_on_protocol=False, **kwargs)

Bases: bob.db.base.Database

This class represents the basic API for database access. Please use this class as a base class for your database access classes. Do not forget to call the constructor of this base class in your derived class.

Parameters:

name : str A unique name for the database.

all_files_options : dict Dictionary of options passed to the bob.bio.db.BioDatabase.objects() database query when retrieving all data.

extractor_training_options : dict Dictionary of options passed to the bob.bio.db.BioDatabase.objects() database query used to retrieve the files for the extractor training.

projector_training_options : dict Dictionary of options passed to the bob.bio.db.BioDatabase.objects() database query used to retrieve the files for the projector training.

enroller_training_options : dict Dictionary of options passed to the bob.bio.db.BioDatabase.objects() database query used to retrieve the files for the enroller training.

check_original_files_for_existence : bool Enables to test for the original data files when querying the database.

original_directory : str The directory where the original data of the database are stored.

original_extension : str The file name extension of the original data.

annotation_directory : str The directory where the image annotations of the database are stored, if any.

annotation_extension : str The file name extension of the annotation files.

annotation_type : str The type of the annotation file to read, see bob.db.base.read_annotation_file for accepted formats.

protocol : str or None The name of the protocol that defines the default experimental setup for this database.

Todo

Check if the None protocol is supported.

training_depends_on_protocol : bool Specifies, if the training set used for training the extractor and the projector depend on the protocol. This flag is used to avoid re-computation of data when running on the different protocols of the same database.

models_depend_on_protocol : bool Specifies, if the models depend on the protocol. This flag is used to avoid re-computation of models when running on the different protocols of the same database.

kwargs : key=value pairs The arguments of the Database base class constructor.

all_files(groups=None) → files[source]

Returns all files of the database, respecting the current protocol. The files can be limited using the all_files_options in the constructor.

Parameters:

groups
: some of ('world', 'dev', 'eval') or None
The groups to get the data for. If None, data for all groups is returned.

Returns:

files
: [bob.bio.db.BioFile]
The sorted and unique list of all files of the database.
annotations(file)[source]

Returns the annotations for the given File object, if available. It uses bob.db.base.read_annotation_file to load the annotations.

Parameters:

file
: bob.bio.db.BioFile
The file for which annotations should be returned.

Returns:

annots
: dict or None
The annotations for the file, if available.
arrange_by_client(files) → files_by_client[source]

Arranges the given list of files by client id. This function returns a list of lists of File’s.

Parameters:

files
: bob.bio.db.BioFile
A list of files that should be split up by BioFile.client_id.

Returns:

files_by_client
: [[bob.bio.db.BioFile]]
The list of lists of files, where each sub-list groups the files with the same BioFile.client_id
check_parameter_for_validity(parameter, parameter_description, valid_parameters, default_parameter=None)

Checks the given parameter for validity

Ensures a given parameter is in the set of valid parameters. If the parameter is None or empty, the value in default_parameter will be returned, in case it is specified, otherwise a ValueError will be raised.

This function will return the parameter after the check tuple or list of parameters, or raise a ValueError.

Parameters:
  • parameter – str The single parameter to be checked. Might be a string or None.
  • parameter_description – str A short description of the parameter. This will be used to raise an exception in case the parameter is not valid.
  • valid_parameters – [str] A list/tuple of valid values for the parameters.
  • default_parameters – [str] or None The default parameter that will be returned in case parameter is None or empty. If omitted and parameter is empty, a ValueError is raised.
check_parameters_for_validity(parameters, parameter_description, valid_parameters, default_parameters=None)

Checks the given parameters for validity.

Checks a given parameter is in the set of valid parameters. It also assures that the parameters form a tuple or a list. If parameters is ‘None’ or empty, the default_parameters will be returned (if default_parameters is omitted, all valid_parameters are returned).

This function will return a tuple or list of parameters, or raise a ValueError.

Parameters:
  • parameters – str, [str] or None The parameters to be checked. Might be a string, a list/tuple of strings, or None.
  • parameter_description – str A short description of the parameter. This will be used to raise an exception in case the parameter is not valid.
  • valid_parameters – [str] A list/tuple of valid values for the parameters.
  • default_parameters – [str] or None The list/tuple of default parameters that will be returned in case parameters is None or empty. If omitted, all valid_parameters are used.
client_id_from_model_id(model_id, group='dev')[source]

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.

convert_names_to_highlevel(names, low_level_names, high_level_names)

Converts group names from a low level to high level API

This is useful for example when you want to return db.groups() for the bob.bio.base. Your instance of the database should already have low_level_names and high_level_names initialized.

convert_names_to_lowlevel(names, low_level_names, high_level_names)

Same as convert_names_to_highlevel but on reverse

enroll_files(model_id, group = 'dev') → files[source]

Returns a list of File objects that should be used to enroll the model with the given model id from the given group, respecting the current protocol. If the model_id is None (the default), enrollment files for all models are returned.

Parameters:

model_id
: int or str
A unique ID that identifies the model.
group
: one of ('dev', 'eval')
The group to get the enrollment files for.

Returns:

files
: [bob.bio.db.BioFile]
The list of files used for to enroll the model with the given model id.
file_names(files, directory, extension) → paths[source]

Returns the full path of the given File objects.

Parameters:

files
: [bob.bio.db.BioFile]
The list of file object to retrieve the file names for.
directory
: str
The base directory, where the files can be found.
extension
: str
The file name extension to add to all files.

Returns:

paths
: [str] or [[str]]
The paths extracted for the files, in the same order. If this database provides file sets, a list of lists of file names is returned, one sub-list for each file set.
model_ids(group = 'dev') → ids[source]

Returns a list of model ids for the given group, respecting the current protocol.

Parameters:

group
: one of ('dev', 'eval')
The group to get the model ids for.

Returns:

ids
: [int] or [str]
The list of (unique) model ids for models of the given group.
model_ids_with_protocol(groups = None, protocol = None, **kwargs) → ids[source]

Returns a list of model ids for the given groups and given protocol.

Parameters:

groups
: one or more of ('world', 'dev', 'eval')
The groups to get the model ids for.

protocol: a protocol name

Returns:

ids
: [int] or [str]
The list of (unique) model ids for the given groups.
object_sets(groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)[source]

This function returns lists of FileSet objects, which fulfill the given restrictions.

Keyword parameters:

groups
: str or [str]
The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)
protocol
The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
purposes
: str or [str]
The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).
model_ids
: [various type]
The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.
objects(groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)[source]

This function returns lists of File objects, which fulfill the given restrictions.

Keyword parameters:

groups
: str or [str]
The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)
protocol
The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
purposes
: str or [str]
The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).
model_ids
: [various type]
The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.
original_file_name(file)[source]

This function returns the original file name for the given File object.

Keyword parameters:

file
: bob.bio.db.BioFile or a derivative
The File objects for which the file name should be retrieved
Return value
: str
The original file name for the given File object
original_file_names(files) → paths[source]

Returns the full path of the original data of the given File objects.

Parameters:

files
: [bob.bio.db.BioFile]
The list of file object to retrieve the original data file names for.

Returns:

paths
: [str] or [[str]]
The paths extracted for the files, in the same order. If this database provides file sets, a list of lists of file names is returned, one sub-list for each file set.
probe_file_sets(model_id = None, group = 'dev') → files[source]

Returns a list of probe FileSet objects, respecting the current protocol. If a model_id is specified, only the probe files that should be compared with the given model id are returned (for most databases, these are all probe files of the given group). Otherwise, all probe files of the given group are returned.

Parameters:

model_id
: int or str or None
A unique ID that identifies the model.
group
: one of ('dev', 'eval')
The group to get the enrollment files for.

Returns:

files
: [bob.bio.db.BioFileSet] or something similar
The list of file sets used to probe the model with the given model id.
probe_files(model_id = None, group = 'dev') → files[source]

Returns a list of probe File objects, respecting the current protocol. If a model_id is specified, only the probe files that should be compared with the given model id are returned (for most databases, these are all probe files of the given group). Otherwise, all probe files of the given group are returned.

Parameters:

model_id
: int or str or None
A unique ID that identifies the model.
group
: one of ('dev', 'eval')
The group to get the enrollment files for.

Returns:

files
: [bob.bio.db.BioFile]
The list of files used for to probe the model with the given model id.
replace_directories(replacements=None)[source]

This helper function replaces the original_directory and the annotation_directory of the database with the directories read from the given replacement file.

This function is provided for convenience, so that the database configuration files do not need to be modified. Instead, this function uses the given dictionary of replacements to change the original directory and the original extension (if given).

The given replacements can be of type dict, including all replacements, or a file name (as a str), in which case the file is read. The structure of the file should be:

# Comments starting with # and empty lines are ignored

[YOUR_..._DATA_DIRECTORY] = /path/to/your/data
[YOUR_..._ANNOTATION_DIRECTORY] = /path/to/your/annotations

If no annotation files are available (e.g. when they are stored inside the database), the annotation directory can be left out.

Parameters:

replacements
: dict or str
A dictionary with replacements, or a name of a file to read the dictionary from. If the file name does not exist, no directories are replaced.
sort(files) → sorted[source]

Returns a sorted version of the given list of File’s (or other structures that define an ‘id’ data member). The files will be sorted according to their id, and duplicate entries will be removed.

Parameters:

files
: [bob.bio.db.BioFile]
The list of files to be uniquified and sorted.

Returns:

sorted
: [bob.bio.db.BioFile]
The sorted list of files, with duplicate BioFile.ids being removed.
test_files(groups = ['dev']) → files[source]

Returns all test files (i.e., files used for enrollment and probing) for the given groups, respecting the current protocol. The files for the steps can be limited using the all_files_options defined in the constructor.

Parameters:

groups
: some of ('dev', 'eval')
The groups to get the data for.

Returns:

files
: [bob.bio.db.BioFile]
The sorted and unique list of test files of the database.
training_files(step = None, arrange_by_client = False) → files[source]

Returns all training files for the given step, and arranges them by client, if desired, respecting the current protocol. The files for the steps can be limited using the ..._training_options defined in the constructor.

Parameters:

step
: one of ('train_extractor', 'train_projector', 'train_enroller') or None
The step for which the training data should be returned.
arrange_by_client
: bool
Should the training files be arranged by client? If set to True, training files will be returned in [[bob.bio.db.BioFile]], where each sub-list contains the files of a single client. Otherwise, all files will be stored in a simple [bob.bio.db.BioFile].

Returns:

files
: [bob.bio.db.BioFile] or [[bob.bio.db.BioFile]]
The (arranged) list of files used for the training of the given step.
uses_probe_file_sets(protocol=None)[source]

Defines if, for the current protocol, the database uses several probe files to generate a score. Returns True if the given protocol specifies file sets for probes, instead of a single probe file. In this default implementation, False is returned, throughout. If you need different behavior, please overload this function in your derived class.

class bob.bio.db.BioFile(client_id, path, file_id=None)

Bases: bob.db.base.File

A simple base class that defines basic properties of File object for the use in verification experiments

load(directory=None, extension='.hdf5')

Loads the data at the specified location and using the given extension. Override it if you need to load differently.

Keyword Parameters:

data
The data blob to be saved (normally a numpy.ndarray).
directory
[optional] If not empty or None, this directory is prefixed to the final file destination
extension
[optional] The extension of the filename - this will control the type of output and the codec for saving the input blob.
make_path(directory=None, extension=None)

Wraps the current path so that a complete path is formed

Keyword Parameters:

directory
An optional directory name that will be prefixed to the returned result.
extension
An optional extension that will be suffixed to the returned filename. The extension normally includes the leading . character as in .jpg or .hdf5.

Returns a string containing the newly generated file path.

save(data, directory=None, extension='.hdf5', create_directories=True)

Saves the input data at the specified location and using the given extension. Override it if you need to save differently.

Keyword Parameters:

data
The data blob to be saved (normally a numpy.ndarray).
directory
[optional] If not empty or None, this directory is prefixed to the final file destination
extension
[optional] The extension of the filename - this will control the type of output and the codec for saving the input blob.
class bob.bio.db.BioFileListDatabase(base_dir, original_directory=None, original_extension=None, annotation_directory=None, annotation_extension='.pos', annotation_type='eyecenter', dev_subdir=None, eval_subdir=None, world_filename=None, optional_world_1_filename=None, optional_world_2_filename=None, models_filename=None, probes_filename=None, scores_filename=None, tnorm_filename=None, znorm_filename=None, use_dense_probe_file_list=None, keep_read_lists_in_memory=True)

Bases: bob.db.base.Database

This class provides a user-friendly interface to databases that are given as file lists.

Keyword parameters:

base_dir
: str
The directory that contains the filelists defining the protocol(s). If you use the protocol attribute when querying the database, it will be appended to the base directory, such that several protocols are supported by the same class instance of bob.bio.db.
original_directory
: str or None
The directory, where the original data can be found
original_extension
: str or [str] or None
The filename extension of the original data, or multiple extensions
annotation_directory
: str or None
The directory, where additional annotation files can be found
annotation_extension
: str or None
The filename extension of the annoation files
annotation_type
: str or None
The type of annotation that can be read. Currently, options are ‘eyecenter’, ‘named’, ‘idiap’. See bob.db.base.read_annotation_file() for details.
dev_subdir
: str or None
Specify a custom subdirectory for the filelists of the development set (default is ‘dev’)
eval_subdir
: str or None
Specify a custom subdirectory for the filelists of the development set (default is ‘eval’)
world_filename
: str or None
Specify a custom filename for the training filelist (default is ‘norm/train_world.lst’)
optional_world_1_filename
: str or None
Specify a custom filename for the (first optional) training filelist (default is ‘norm/train_optional_world_1.lst’)
optional_world_2_filename
: str or None
Specify a custom filename for the (second optional) training filelist (default is ‘norm/train_optional_world_2.lst’)
models_filename
: str or None
Specify a custom filename for the model filelists (default is ‘for_models.lst’)
probes_filename
: str or None
Specify a custom filename for the probes filelists (default is ‘for_probes.lst’)
scores_filename
: str or None
Specify a custom filename for the scores filelists (default is ‘for_scores.lst’)
tnorm_filename
: str or None
Specify a custom filename for the T-norm scores filelists (default is ‘for_tnorm.lst’)
znorm_filename
: str or None
Specify a custom filename for the Z-norm scores filelists (default is ‘for_znorm.lst’)
use_dense_probe_file_list
: bool or None
Specify which list to use among ‘probes_filename’ (dense) or ‘scores_filename’. If None it is tried to be estimated based on the given parameters.
keep_read_lists_in_memory
: bool
If set to true, the lists are read only once and stored in memory
annotations(file)[source]

Reads the annotations for the given file id from file and returns them in a dictionary.

If you don’t have a copy of the annotation files, you can download them under http://www.idiap.ch/resource/biometric.

Keyword parameters:

file
: bob.bio.db.File
The File object for which the annotations should be read.
Return value
The annotations as a dictionary: {‘reye’:(re_y,re_x), ‘leye’:(le_y,le_x)}
check_parameter_for_validity(parameter, parameter_description, valid_parameters, default_parameter=None)

Checks the given parameter for validity

Ensures a given parameter is in the set of valid parameters. If the parameter is None or empty, the value in default_parameter will be returned, in case it is specified, otherwise a ValueError will be raised.

This function will return the parameter after the check tuple or list of parameters, or raise a ValueError.

Parameters:
  • parameter – str The single parameter to be checked. Might be a string or None.
  • parameter_description – str A short description of the parameter. This will be used to raise an exception in case the parameter is not valid.
  • valid_parameters – [str] A list/tuple of valid values for the parameters.
  • default_parameters – [str] or None The default parameter that will be returned in case parameter is None or empty. If omitted and parameter is empty, a ValueError is raised.
check_parameters_for_validity(parameters, parameter_description, valid_parameters, default_parameters=None)

Checks the given parameters for validity.

Checks a given parameter is in the set of valid parameters. It also assures that the parameters form a tuple or a list. If parameters is ‘None’ or empty, the default_parameters will be returned (if default_parameters is omitted, all valid_parameters are returned).

This function will return a tuple or list of parameters, or raise a ValueError.

Parameters:
  • parameters – str, [str] or None The parameters to be checked. Might be a string, a list/tuple of strings, or None.
  • parameter_description – str A short description of the parameter. This will be used to raise an exception in case the parameter is not valid.
  • valid_parameters – [str] A list/tuple of valid values for the parameters.
  • default_parameters – [str] or None The list/tuple of default parameters that will be returned in case parameters is None or empty. If omitted, all valid_parameters are used.
client_ids(protocol=None, groups=None)[source]

Returns a list of client ids for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the clients belong (“dev”, “eval”, “world”, “optional_world_1”, “optional_world_2”).

Returns: A list containing all the client ids which have the given properties.

clients(protocol=None, groups=None)[source]

Returns a list of Client objects for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the clients belong (“dev”, “eval”, “world”, “optional_world_1”, “optional_world_2”).

Returns: A list containing all the Client objects which have the given properties.

convert_names_to_highlevel(names, low_level_names, high_level_names)

Converts group names from a low level to high level API

This is useful for example when you want to return db.groups() for the bob.bio.base. Your instance of the database should already have low_level_names and high_level_names initialized.

convert_names_to_lowlevel(names, low_level_names, high_level_names)

Same as convert_names_to_highlevel but on reverse

get_base_directory()[source]

Returns the base directory where the filelists defining the database are located.

get_client_id_from_model_id(model_id, groups=None, protocol=None)[source]

Returns the client id that is connected to the given model id.

Keyword parameters:

model_id
: str or None
The model id for which the client id should be returned.
groups
: str or [str] or None
(optional) the groups, the client belongs to. Might be one or more of (‘dev’, ‘eval’, ‘world’, ‘optional_world_1’, ‘optional_world_2’). If groups are given, only these groups are considered.
protocol
: str or None
The protocol to consider

Returns: The client id for the given model id, if found.

get_client_id_from_tmodel_id(model_id, groups=None, protocol=None)[source]

Returns the client id that is connected to the given T-Norm model id.

Keyword parameters:

model_id
: str or None
The model id for which the client id should be returned.
groups
: str or [str] or None
(optional) the groups, the client belongs to. Might be one or more of (‘dev’, ‘eval’). If groups are given, only these groups are considered.
protocol
: str or None
The protocol to consider

Returns: The client id for the given model id of a T-Norm model, if found.

get_list_file(group, type=None, protocol=None)[source]
groups(protocol=None)[source]

This function returns the list of groups for this database.

protocol
: str or None
The protocol for which the groups should be retrieved.

Returns: a list of groups

implements_zt(protocol=None, groups=None)[source]

Checks if the file lists for the ZT score normalization are available.

Keyword Parameters:

protocol
: str or None
The protocol for which the groups should be retrieved.
groups
: str or [str] or None
The groups for which the ZT score normalization file lists should be checked (“dev”, “eval”).
Returns:True if the all file lists for ZT score normalization exist, otherwise False.
model_ids(protocol=None, groups=None)[source]

Returns a list of model ids for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the models belong (“dev”, “eval”, “world”, “optional_world_1”, “optional_world_2”).

Returns: A list containing all the model ids which have the given properties.

objects(protocol=None, purposes=None, model_ids=None, groups=None, classes=None)[source]

Returns a set of File objects for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
purposes
: str or [str] or None
The purposes required to be retrieved (“enroll”, “probe”) or a tuple with several of them. If ‘None’ is given (this is the default), it is considered the same as a tuple with all possible values. This field is ignored for the data from the “world”, “optional_world_1”, “optional_world_2” groups.
model_ids
: str or [str] or None
Only retrieves the files for the provided list of model ids (claimed client id). If ‘None’ is given (this is the default), no filter over the model_ids is performed.
groups
: str or [str] or None
One of the groups (“dev”, “eval”, “world”, “optional_world_1”, “optional_world_2”) or a tuple with several of them. If ‘None’ is given (this is the default), it is considered the same as a tuple with all possible values.
classes
: str or [str] or None
The classes (types of accesses) to be retrieved (‘client’, ‘impostor’) or a tuple with several of them. If ‘None’ is given (this is the default), it is considered the same as a tuple with all possible values. Note: classes are not allowed to be specified when the ‘probes_filename’ is used.

Returns: A list of File objects considering all the filtering criteria.

original_file_name(file, check_existence=True)[source]

Returns the original file name of the given file.

This interface supports several original extensions, so that file lists can contain images of different data types.

When multiple original extensions are specified, this function will check the existence of any of these file names, and return the first one that actually exists. In this case, the check_existence flag is ignored.

Keyword parameters

file
: bob.bio.db.File
The py:class:File object for which the file name should be returned.
check_existence
: bool
Should the existence of the original file be checked? (Ignored when multiple original extensions were specified in the contructor.)

Returns str : The full path of the original data file.

set_base_directory(base_dir)[source]

Resets the base directory where the filelists defining the database are located.

tclient_ids(protocol=None, groups=None)[source]

Returns a list of T-Norm client ids for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the clients belong (“dev”, “eval”).

Returns: A list containing all the T-Norm client ids which have the given properties.

tclients(protocol=None, groups=None)[source]

Returns a list of T-Norm Client objects for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the clients belong (“dev”, “eval”).

Returns: A list containing all the T-Norm Client objects which have the given properties.

tmodel_ids(protocol=None, groups=None)[source]

Returns a list of T-Norm model ids for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the models belong (“dev”, “eval”).

Returns: A list containing all the T-Norm model ids belonging to the given group.

tobjects(protocol=None, model_ids=None, groups=None)[source]

Returns a list of File objects for enrolling T-norm models for score normalization.

Keyword Parameters:

protocol
: str or None
The protocol to consider
model_ids
: str or [str] or None
Only retrieves the files for the provided list of model ids (claimed client id). If ‘None’ is given (this is the default), no filter over the model_ids is performed.
groups
: str or [str] or None
The groups to which the models belong (“dev”, “eval”).

Returns: A list of File objects considering all the filtering criteria.

zclient_ids(protocol=None, groups=None)[source]

Returns a list of Z-Norm client ids for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the clients belong (“dev”, “eval”).

Returns: A list containing all the Z-Norm client ids which have the given properties.

zclients(protocol=None, groups=None)[source]

Returns a list of Z-Norm Client objects for the specific query by the user.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the models belong (“dev”, “eval”).

Returns: A list containing all the Z-Norm Client objects which have the given properties.

zobjects(protocol=None, groups=None)[source]

Returns a list of File objects to perform Z-norm score normalization.

Keyword Parameters:

protocol
: str or None
The protocol to consider
groups
: str or [str] or None
The groups to which the clients belong (“dev”, “eval”).

Returns: A list of File objects considering all the filtering criteria.

class bob.bio.db.BioFileSet(file_set_id, files, path=None)

Bases: bob.bio.db.BioFile

This class defines the minimum interface of a set of database files that needs to be exported. Use this class, whenever the database provides several files that belong to the same probe. Each file set has an id, and a list of associated files, which are of type bob.bio.db.BioFile of the same client. The file set id can be anything hashable, but needs to be unique all over the database.

Parameters:

file_set_id
: str or int
A unique ID that identifies the file set.
files
: [bob.bio.db.BioFile]
A non-empty list of BioFile objects that should be stored inside this file. All files of that list need to have the same client ID.
load(directory=None, extension='.hdf5')

Loads the data at the specified location and using the given extension. Override it if you need to load differently.

Keyword Parameters:

data
The data blob to be saved (normally a numpy.ndarray).
directory
[optional] If not empty or None, this directory is prefixed to the final file destination
extension
[optional] The extension of the filename - this will control the type of output and the codec for saving the input blob.
make_path(directory=None, extension=None)

Wraps the current path so that a complete path is formed

Keyword Parameters:

directory
An optional directory name that will be prefixed to the returned result.
extension
An optional extension that will be suffixed to the returned filename. The extension normally includes the leading . character as in .jpg or .hdf5.

Returns a string containing the newly generated file path.

save(data, directory=None, extension='.hdf5', create_directories=True)

Saves the input data at the specified location and using the given extension. Override it if you need to save differently.

Keyword Parameters:

data
The data blob to be saved (normally a numpy.ndarray).
directory
[optional] If not empty or None, this directory is prefixed to the final file destination
extension
[optional] The extension of the filename - this will control the type of output and the codec for saving the input blob.
class bob.bio.db.Client(client_id)

Bases: object

The clients of this database contain ONLY client ids. Nothing special.

class bob.bio.db.File(file_name, client_id, model_id=None, claimed_id=None)

Bases: bob.bio.db.BioFile

Initialize the File object with the minimum required data.

If the model_id is not specified, model_id and client_id are identical. If the claimed_id is not specified, it is expected to be the client_id.

Parameters

client_id
: various type
The id of the client, this file belongs to. The type of it is dependent on your implementation. If you use an SQL database, this should be an SQL type like Integer or String.
path
: str
The path of this file, relative to the basic directory. If you use an SQL database, this should be the SQL type String. Please do not specify any file extensions.
file_id
: various type
The id of the file. The type of it is dependent on your implementation. If you use an SQL database, this should be an SQL type like Integer or String. If you are using an automatically determined file id, you can skip selecting the file id.
load(directory=None, extension='.hdf5')[source]

Loads the data at the specified location and using the given extension. Override it if you need to load differently.

Keyword Parameters:

data
The data blob to be saved (normally a numpy.ndarray).
directory
[optional] If not empty or None, this directory is prefixed to the final file destination
extension
[optional] The extension of the filename - this will control the type of output and the codec for saving the input blob.
make_path(directory=None, extension=None)[source]

Wraps the current path so that a complete path is formed

Keyword Parameters:

directory
An optional directory name that will be prefixed to the returned result.
extension
An optional extension that will be suffixed to the returned filename. The extension normally includes the leading . character as in .jpg or .hdf5.

Returns a string containing the newly generated file path.

save(data, directory=None, extension='.hdf5', create_directories=True)[source]

Saves the input data at the specified location and using the given extension. Override it if you need to save differently.

Keyword Parameters:

data
The data blob to be saved (normally a numpy.ndarray).
directory
[optional] If not empty or None, this directory is prefixed to the final file destination
extension
[optional] The extension of the filename - this will control the type of output and the codec for saving the input blob.
class bob.bio.db.ZTBioDatabase(name, z_probe_options={}, **kwargs)

Bases: bob.bio.db.BioDatabase

This class defines another set of abstract functions that need to be implemented if your database provides the interface for computing scores used for ZT-normalization.

all_files(groups=None) → files[source]

Returns all files of the database, including those for ZT norm, respecting the current protocol. The files can be limited using the all_files_options and the the z_probe_options in the constructor.

Parameters:

groups
: some of ('world', 'dev', 'eval') or None
The groups to get the data for. If None, data for all groups is returned.

Returns:

files
: [bob.bio.db.BioFile]
The sorted and unique list of all files of the database.
annotations(file)

Returns the annotations for the given File object, if available. It uses bob.db.base.read_annotation_file to load the annotations.

Parameters:

file
: bob.bio.db.BioFile
The file for which annotations should be returned.

Returns:

annots
: dict or None
The annotations for the file, if available.
arrange_by_client(files) → files_by_client

Arranges the given list of files by client id. This function returns a list of lists of File’s.

Parameters:

files
: bob.bio.db.BioFile
A list of files that should be split up by BioFile.client_id.

Returns:

files_by_client
: [[bob.bio.db.BioFile]]
The list of lists of files, where each sub-list groups the files with the same BioFile.client_id
check_parameter_for_validity(parameter, parameter_description, valid_parameters, default_parameter=None)

Checks the given parameter for validity

Ensures a given parameter is in the set of valid parameters. If the parameter is None or empty, the value in default_parameter will be returned, in case it is specified, otherwise a ValueError will be raised.

This function will return the parameter after the check tuple or list of parameters, or raise a ValueError.

Parameters:
  • parameter – str The single parameter to be checked. Might be a string or None.
  • parameter_description – str A short description of the parameter. This will be used to raise an exception in case the parameter is not valid.
  • valid_parameters – [str] A list/tuple of valid values for the parameters.
  • default_parameters – [str] or None The default parameter that will be returned in case parameter is None or empty. If omitted and parameter is empty, a ValueError is raised.
check_parameters_for_validity(parameters, parameter_description, valid_parameters, default_parameters=None)

Checks the given parameters for validity.

Checks a given parameter is in the set of valid parameters. It also assures that the parameters form a tuple or a list. If parameters is ‘None’ or empty, the default_parameters will be returned (if default_parameters is omitted, all valid_parameters are returned).

This function will return a tuple or list of parameters, or raise a ValueError.

Parameters:
  • parameters – str, [str] or None The parameters to be checked. Might be a string, a list/tuple of strings, or None.
  • parameter_description – str A short description of the parameter. This will be used to raise an exception in case the parameter is not valid.
  • valid_parameters – [str] A list/tuple of valid values for the parameters.
  • default_parameters – [str] or None The list/tuple of default parameters that will be returned in case parameters is None or empty. If omitted, all valid_parameters are used.
client_id_from_model_id(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.

client_id_from_t_model_id(t_model_id, group = 'dev') → client_id[source]

Returns the client id for the given T-Norm model id. In this base class implementation, we just use the client_id_from_model_id() function. Overload this function if you need another behavior.

Parameters:

t_model_id
: int or str
A unique ID that identifies the T-Norm model.
group
: one of ('dev', 'eval')
The group to get the client ids for.

Returns:

client_id
: [int] or [str]
A unique ID that identifies the client, to which the T-Norm model belongs.
convert_names_to_highlevel(names, low_level_names, high_level_names)

Converts group names from a low level to high level API

This is useful for example when you want to return db.groups() for the bob.bio.base. Your instance of the database should already have low_level_names and high_level_names initialized.

convert_names_to_lowlevel(names, low_level_names, high_level_names)

Same as convert_names_to_highlevel but on reverse

enroll_files(model_id, group = 'dev') → files

Returns a list of File objects that should be used to enroll the model with the given model id from the given group, respecting the current protocol. If the model_id is None (the default), enrollment files for all models are returned.

Parameters:

model_id
: int or str
A unique ID that identifies the model.
group
: one of ('dev', 'eval')
The group to get the enrollment files for.

Returns:

files
: [bob.bio.db.BioFile]
The list of files used for to enroll the model with the given model id.
file_names(files, directory, extension) → paths

Returns the full path of the given File objects.

Parameters:

files
: [bob.bio.db.BioFile]
The list of file object to retrieve the file names for.
directory
: str
The base directory, where the files can be found.
extension
: str
The file name extension to add to all files.

Returns:

paths
: [str] or [[str]]
The paths extracted for the files, in the same order. If this database provides file sets, a list of lists of file names is returned, one sub-list for each file set.
model_ids(group = 'dev') → ids

Returns a list of model ids for the given group, respecting the current protocol.

Parameters:

group
: one of ('dev', 'eval')
The group to get the model ids for.

Returns:

ids
: [int] or [str]
The list of (unique) model ids for models of the given group.
model_ids_with_protocol(groups = None, protocol = None, **kwargs) → ids

Returns a list of model ids for the given groups and given protocol.

Parameters:

groups
: one or more of ('world', 'dev', 'eval')
The groups to get the model ids for.

protocol: a protocol name

Returns:

ids
: [int] or [str]
The list of (unique) model ids for the given groups.
object_sets(groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)

This function returns lists of FileSet objects, which fulfill the given restrictions.

Keyword parameters:

groups
: str or [str]
The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)
protocol
The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
purposes
: str or [str]
The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).
model_ids
: [various type]
The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.
objects(groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)

This function returns lists of File objects, which fulfill the given restrictions.

Keyword parameters:

groups
: str or [str]
The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)
protocol
The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
purposes
: str or [str]
The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).
model_ids
: [various type]
The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.
original_file_name(file)

This function returns the original file name for the given File object.

Keyword parameters:

file
: bob.bio.db.BioFile or a derivative
The File objects for which the file name should be retrieved
Return value
: str
The original file name for the given File object
original_file_names(files) → paths

Returns the full path of the original data of the given File objects.

Parameters:

files
: [bob.bio.db.BioFile]
The list of file object to retrieve the original data file names for.

Returns:

paths
: [str] or [[str]]
The paths extracted for the files, in the same order. If this database provides file sets, a list of lists of file names is returned, one sub-list for each file set.
probe_file_sets(model_id = None, group = 'dev') → files

Returns a list of probe FileSet objects, respecting the current protocol. If a model_id is specified, only the probe files that should be compared with the given model id are returned (for most databases, these are all probe files of the given group). Otherwise, all probe files of the given group are returned.

Parameters:

model_id
: int or str or None
A unique ID that identifies the model.
group
: one of ('dev', 'eval')
The group to get the enrollment files for.

Returns:

files
: [bob.bio.db.BioFileSet] or something similar
The list of file sets used to probe the model with the given model id.
probe_files(model_id = None, group = 'dev') → files

Returns a list of probe File objects, respecting the current protocol. If a model_id is specified, only the probe files that should be compared with the given model id are returned (for most databases, these are all probe files of the given group). Otherwise, all probe files of the given group are returned.

Parameters:

model_id
: int or str or None
A unique ID that identifies the model.
group
: one of ('dev', 'eval')
The group to get the enrollment files for.

Returns:

files
: [bob.bio.db.BioFile]
The list of files used for to probe the model with the given model id.
replace_directories(replacements=None)

This helper function replaces the original_directory and the annotation_directory of the database with the directories read from the given replacement file.

This function is provided for convenience, so that the database configuration files do not need to be modified. Instead, this function uses the given dictionary of replacements to change the original directory and the original extension (if given).

The given replacements can be of type dict, including all replacements, or a file name (as a str), in which case the file is read. The structure of the file should be:

# Comments starting with # and empty lines are ignored

[YOUR_..._DATA_DIRECTORY] = /path/to/your/data
[YOUR_..._ANNOTATION_DIRECTORY] = /path/to/your/annotations

If no annotation files are available (e.g. when they are stored inside the database), the annotation directory can be left out.

Parameters:

replacements
: dict or str
A dictionary with replacements, or a name of a file to read the dictionary from. If the file name does not exist, no directories are replaced.
sort(files) → sorted

Returns a sorted version of the given list of File’s (or other structures that define an ‘id’ data member). The files will be sorted according to their id, and duplicate entries will be removed.

Parameters:

files
: [bob.bio.db.BioFile]
The list of files to be uniquified and sorted.

Returns:

sorted
: [bob.bio.db.BioFile]
The sorted list of files, with duplicate BioFile.ids being removed.
t_enroll_files(t_model_id, group = 'dev') → files[source]

Returns a list of File objects that should be used to enroll the T-Norm model with the given model id from the given group, respecting the current protocol.

Parameters:

t_model_id
: int or str
A unique ID that identifies the model.
group
: one of ('dev', 'eval')
The group to get the enrollment files for.

Returns:

files
: [bob.bio.db.BioFile]
The sorted list of files used for to enroll the model with the given model id.
t_model_ids(group = 'dev') → ids[source]

Returns a list of model ids of T-Norm models for the given group, respecting the current protocol.

Parameters:

group
: one of ('dev', 'eval')
The group to get the model ids for.

Returns:

ids
: [int] or [str]
The list of (unique) model ids for T-Norm models of the given group.
test_files(groups = ['dev']) → files

Returns all test files (i.e., files used for enrollment and probing) for the given groups, respecting the current protocol. The files for the steps can be limited using the all_files_options defined in the constructor.

Parameters:

groups
: some of ('dev', 'eval')
The groups to get the data for.

Returns:

files
: [bob.bio.db.BioFile]
The sorted and unique list of test files of the database.
tmodel_ids_with_protocol(protocol=None, groups=None, **kwargs)[source]

This function returns the ids of the T-Norm models of the given groups for the given protocol.

Keyword parameters:

groups
: str or [str]
The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)
protocol
: str
The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
tobjects(groups=None, protocol=None, model_ids=None, **kwargs)[source]

This function returns the File objects of the T-Norm models of the given groups for the given protocol and the given model ids.

Keyword parameters:

groups
: str or [str]
The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)
protocol
: str
The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
model_ids
: [various type]
The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.
training_files(step = None, arrange_by_client = False) → files

Returns all training files for the given step, and arranges them by client, if desired, respecting the current protocol. The files for the steps can be limited using the ..._training_options defined in the constructor.

Parameters:

step
: one of ('train_extractor', 'train_projector', 'train_enroller') or None
The step for which the training data should be returned.
arrange_by_client
: bool
Should the training files be arranged by client? If set to True, training files will be returned in [[bob.bio.db.BioFile]], where each sub-list contains the files of a single client. Otherwise, all files will be stored in a simple [bob.bio.db.BioFile].

Returns:

files
: [bob.bio.db.BioFile] or [[bob.bio.db.BioFile]]
The (arranged) list of files used for the training of the given step.
uses_probe_file_sets(protocol=None)

Defines if, for the current protocol, the database uses several probe files to generate a score. Returns True if the given protocol specifies file sets for probes, instead of a single probe file. In this default implementation, False is returned, throughout. If you need different behavior, please overload this function in your derived class.

z_probe_file_sets(group = 'dev') → files[source]

Returns a list of probe FileSet objects used to compute the Z-Norm. This function needs to be implemented in derived class implementations.

Parameters:

group
: one of ('dev', 'eval')
The group to get the Z-norm probe files for.

Returns:

files
: [bob.bio.db.BioFileSet]
The unique list of file sets used to compute the Z-norm.
z_probe_files(group = 'dev') → files[source]

Returns a list of probe files used to compute the Z-Norm, respecting the current protocol. The Z-probe files can be limited using the z_probe_options in the query to bob.bio.db.ZTBioDatabase.z_probe_files()

Parameters:

group
: one of ('dev', 'eval')
The group to get the Z-norm probe files for.

Returns:

files
: [bob.bio.db.BioFile]
The unique list of files used to compute the Z-norm.
zobjects(groups=None, protocol=None, **kwargs)[source]

This function returns the File objects of the Z-Norm impostor files of the given groups for the given protocol.

Keyword parameters:

groups
: str or [str]
The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)
protocol
: str
The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.