Python API¶
This is the Bob database entry for the Labeled Faces in the Wild (LFW) database.
-
class
bob.db.lfw.Annotation(file_id, annotation_type, annotations)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base-
annotation_type¶
-
annotation_type_choices= ('funneled', 'idiap')¶
-
annotations¶
-
file_id¶
-
id¶
-
metadata= MetaData(bind=None)¶
-
-
class
bob.db.lfw.Client(name)[source]¶ Bases:
sqlalchemy.ext.declarative.api.BaseInformation about the clients (identities) of the LFW database.
-
id¶
-
metadata= MetaData(bind=None)¶
-
-
class
bob.db.lfw.Database(original_directory=None, original_extension='.jpg', annotation_type=None)[source]¶ Bases:
bob.db.verification.utils.database.SQLiteDatabaseThe dataset class opens and maintains a connection opened to the Database.
It provides many different ways to probe for the characteristics of the data and for the data itself inside the database.
-
all_files(**kwargs)[source]¶ Returns the list of all File objects that satisfy your query. For possible keyword arguments, please check the
objects()function.
-
annotations(file, annotation_type=None)[source]¶ Returns the annotations for the given file id as a dictionary, e.g. {‘reye’:(y,x), ‘leye’:(y,x)}.
Keyword parameters:
- file_id
- The
Fileobject for which you want to retrieve the annotations - annotation_type
- The type of annotations (‘idiap’, ‘funneled’). If not specified, and if not given in the constructor, all annotations are taken, which might to cause an assertion error.
-
assert_validity()¶ Raise a RuntimeError if the database back-end is not available.
-
check_parameter_for_validity(parameter, parameter_description, valid_parameters, default_parameter=None)[source]¶ Checks the given parameter for validity, i.e., if it is contained in the set of valid parameters. If the parameter is ‘None’ or empty, the 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.
Keyword 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)[source]¶ Checks the given parameters for validity, i.e., if they are contained 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.
Keyword 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.
-
clients(protocol=None, groups=None, subworld='sevenfolds', world_type='unrestricted')[source]¶ Returns a list of Client objects for the specific query by the user.
Keyword Parameters:
- protocol
- The protocol to consider; one of: (‘view1’, ‘fold1’, ..., ‘fold10’), or None
- groups
- The groups to which the clients belong; one or several of: (‘world’, ‘dev’, ‘eval’) Note: the ‘eval’ group does not exist for protocol ‘view1’.
- subworld
- The subset of the training data. Has to be specified if groups includes ‘world’ and protocol is one of ‘fold1’, ..., ‘fold10’. It might be exactly one of (‘onefolds’, ‘twofolds’, ..., ‘sevenfolds’). Ignored for group ‘dev’ and ‘eval’.
- world_type
- One of (‘restricted’, ‘unrestricted’). If ‘restricted’ (the default), only the clients that are used in one of the training pairs are returned. For ‘unrestricted’, all training people are returned. Ignored for group ‘dev’ and ‘eval’.
Returns: A list containing all Client objects which have the desired properties.
-
enroll_files(protocol=None, model_id=None, groups='dev', **kwargs)[source]¶ Returns the list of enrollment File objects from the given model id of the given protocol for the given groups that satisfy your query. If the model_id is None (the default), enrollment files for all models are returned. For possible keyword arguments, please check the
objects()function.
-
file_names(files, directory, extension)[source]¶ This function returns the list of original file names for the given list of File objects.
Keyword parameters:
- files : [
File] - The list of File objects for which the file names should be retrieved
- directory : str
- The base directory where the files are stored
- extension : str
- The file name extension of the files
- Return value : [str]
- The file names for the given File objects, in the same order.
- files : [
-
files(ids, preserve_order=True)¶ Returns a list of
Fileobjects with the given file idsKeyword Parameters:
- ids : [various type]
- The ids of the object in the database table “file”. This object should be a python iterable (such as a tuple or list).
- preserve_order : bool
- If True (the default) the order of elements is preserved, but the execution time increases.
Returns a list (that may be empty) of
Fileobjects.
-
get_client_id_from_file_id(file_id, **kwargs)[source]¶ Returns the client_id (real client id) attached to the given file_id
Keyword Parameters:
- file_id
- The file_id to consider
Returns: The client_id attached to the given file_id
-
get_client_id_from_model_id(model_id, **kwargs)[source]¶ Returns the client_id (real client id) attached to the given model id
Keyword Parameters:
- model_id
- The model to consider
- type
- One of (‘restricted’, ‘unrestricted’). If the type ‘restricted’ is given, model_ids will be handled as file ids, if type is ‘unrestricted’, model ids will be client ids.
Returns: The client_id attached to the given model
-
is_valid()¶ Returns if a valid session has been opened for reading the database.
-
model_ids(protocol=None, groups=None)[source]¶ Returns a list of model ids for the specific query by the user. For the ‘dev’ and ‘eval’ groups, the first element of each pair is extracted.
Keyword Parameters:
- protocol
- The protocol to consider; one of: (‘view1’, ‘fold1’, ..., ‘fold10’), or None
- groups
- The groups to which the clients belong; one or several of: (‘dev’, ‘eval’) The ‘eval’ group does not exist for protocol ‘view1’.
Returns: A list containing all model ids which have the desired properties.
-
models(protocol=None, groups=None)[source]¶ Returns a list of File objects (there are multiple models per client) for the specific query by the user. For the ‘dev’ and ‘eval’ groups, the first element of each pair is extracted.
Keyword Parameters:
- protocol
- The protocol to consider; one of: (‘view1’, ‘fold1’, ..., ‘fold10’), or None
- groups
- The groups to which the clients belong; one or several of: (‘dev’, ‘eval’) The ‘eval’ group does not exist for protocol ‘view1’.
Returns: A list containing all File objects which have the desired properties.
-
objects(protocol=None, model_ids=None, groups=None, purposes=None, subworld='sevenfolds', world_type='unrestricted')[source]¶ Returns a list of File objects for the specific query by the user.
Keyword Parameters:
- protocol
- The protocol to consider (‘view1’, ‘fold1’, ..., ‘fold10’), or None
- groups
- The groups to which the objects belong (‘world’, ‘dev’, ‘eval’)
- purposes
- The purposes of the objects (‘enroll’, ‘probe’)
- subworld
- The subset of the training data. Has to be specified if groups includes ‘world’ and protocol is one of ‘fold1’, ..., ‘fold10’. It might be exactly one of (‘onefolds’, ‘twofolds’, ..., ‘sevenfolds’).
- world_type
- One of (‘restricted’, ‘unrestricted’). If ‘restricted’, only the files that are used in one of the training pairs are used. For ‘unrestricted’, all files of the training people are returned.
- model_ids
- Only retrieves the objects for the provided list of model ids. If ‘None’ is given (this is the default), no filter over the model_ids is performed. Note that the combination of ‘world’ group and ‘model_ids’ should be avoided.
Returns: A list of File objects considering all the filtering criteria.
-
original_file_name(file, check_existence=True)[source]¶ This function returns the original file name for the given File object.
Keyword parameters:
- file :
Fileor a derivative - The File objects for which the file name should be retrieved
- check_existence : bool
- Check if the original file exists?
- Return value : str
- The original file name for the given File object
- file :
-
original_file_names(files, check_existence=True)[source]¶ This function returns the list of original file names for the given list of File objects.
Keyword parameters:
- files : [
File] - The list of File objects for which the file names should be retrieved
- check_existence : bool
- Check if the original files exists?
- Return value : [str]
- The original file names for the given File objects, in the same order.
- files : [
-
pairs(protocol=None, groups=None, classes=None, subworld='sevenfolds')[source]¶ Queries a list of Pair’s of files.
Keyword Parameters:
- protocol
- The protocol to consider (‘view1’, ‘fold1’, ..., ‘fold10’)
- groups
- The groups to which the objects belong (‘world’, ‘dev’, ‘eval’)
- classes
- The classes to which the pairs belong (‘matched’, ‘unmatched’), or (‘client’, ‘impostor’)
- subworld
- The subset of the training data. Has to be specified if groups includes ‘world’ and protocol is one of ‘fold1’, ..., ‘fold10’. It might be exactly one of (‘onefolds’, ‘twofolds’, ..., ‘sevenfolds’).
Returns: A list of Pair’s considering all the filtering criteria.
-
paths(ids, prefix=None, suffix=None, preserve_order=True)¶ Returns a full file paths considering particular file ids, a given directory and an extension
Keyword Parameters:
- ids : [various type]
- The ids of the object in the database table “file”. This object should be a python iterable (such as a tuple or list).
- prefix : str or None
- The bit of path to be prepended to the filename stem
- suffix : str or None
- The extension determines the suffix that will be appended to the filename stem.
- preserve_order : bool
- If True (the default) the order of elements is preserved, but the execution time increases.
Returns a list (that may be empty) of the fully constructed paths given the file ids.
-
probe_files(protocol=None, model_id=None, groups='dev', **kwargs)[source]¶ Returns the list of probe File objects to probe the model with the given model id of the given protocol for the given groups that satisfy your query. If the model_id is None (the default), all possible probe files are returned. For possible keyword arguments, please check the
objects()function.
-
provides_file_set_for_protocol(protocol=None)[source]¶ 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.
-
query(*args)¶ Creates a query to the database using the given arguments.
-
reverse(paths, preserve_order=True)¶ Reverses the lookup: from certain paths, return a list of File objects
Keyword Parameters:
- paths : [str]
- The filename stems to query for. This object should be a python iterable (such as a tuple or list)
- preserve_order : True
- If True (the default) the order of elements is preserved, but the execution time increases.
Returns a list (that may be empty).
-
subworld_names(protocol=None)[source]¶ Returns all valid sub-worlds for the fold.. protocols; for view1 an empty list is returned.
-
test_files(protocol=None, groups='dev', **kwargs)[source]¶ Returns the list of all test File objects of the given groups that satisfy your query. Test objects are all File objects that serve either for enrollment or probing. For possible keyword arguments, please check the
objects()function.
-
training_files(protocol=None, **kwargs)[source]¶ Returns the list of all training (world) File objects that satisfy your query. For possible keyword arguments, please check the
objects()function.
-
uniquify(file_list)[source]¶ Sorts the given list of File objects and removes duplicates from it.
Keyword parameters:
- file_list : [
File] - A list of File objects to be handled. Also other objects can be handled, as long as they are sortable.
- Returns
- A sorted copy of the given
file_listwith the duplicates removed.
- file_list : [
-
-
class
bob.db.lfw.File(client_id, shot_id)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base,bob.db.verification.utils.file.FileInformation about the files of the LFW database.
-
annotations¶
-
client¶
-
client_id¶
-
id¶
-
make_path(directory=None, extension=None)[source]¶ Wraps the current path so that a complete path is formed
Keyword parameters:
- directory : str or None
- An optional directory name that will be prefixed to the returned result.
- extension : str or None
- An optional extension that will be suffixed to the returned filename.
The extension normally includes the leading
.character as in.jpgor.hdf5.
Returns a string containing the newly generated file path.
-
metadata= MetaData(bind=None)¶
-
name¶
-
path¶
-
save(data, directory=None, extension='.hdf5', create_directories=True)[source]¶ Saves the input data at the specified location and using the given extension.
Keyword parameters:
- data : various types
- The data blob to be saved (normally a
numpy.ndarray). - directory : str or None
- If not empty or None, this directory is prefixed to the final file destination
- extension : str or None
- The extension of the filename. This extension will control the type of output and the codec for saving the input blob.
- create_directories : bool
- Should the directory structure be created (if necessary) before writing the data?
-
shot_id¶
-
-
class
bob.db.lfw.Pair(protocol, enroll_file_id, probe_file_id, is_match)[source]¶ Bases:
sqlalchemy.ext.declarative.api.BaseInformation of the pairs (as given in the pairs.txt files) of the LFW database.
-
enroll_file¶
-
enroll_file_id¶
-
id¶
-
is_match¶
-
metadata= MetaData(bind=None)¶
-
probe_file¶
-
probe_file_id¶
-
protocol¶
-