Python API¶
-
bob.db.casia_webface.get_config()[source]¶ Returns a string containing the configuration information.
-
class
bob.db.casia_webface.Client(id, name)[source]¶ Bases:
sqlalchemy.ext.declarative.api.BaseDatabase clients, marked by an integer identifier and the group they belong to
-
id¶
-
metadata= MetaData(bind=None)¶
-
name¶
-
-
class
bob.db.casia_webface.Database(original_directory=None, lfw_directory=None, original_extension=None)[source]¶ Bases:
bob.db.base.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)¶ Returns the list of all File objects that satisfy your query.
For possible keyword arguments, please check the implemention’s
objects()method.
-
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
Ensures a given parameter is in the set of valid parameters. If the parameter is
Noneor empty, the value indefault_parameterwill be returned, in case it is specified, otherwise aValueErrorwill 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)[source]¶ 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.
-
clients(protocol=None, groups=None)[source]¶ Returns a set of clients for the specific query by the user.
Keyword Parameters:
- protocol
- Ignored since the clients are identical for all protocols.
- groups
- The groups to which the clients
Returns: A list containing all the clients which have the given properties.
-
convert_names_to_highlevel(names, low_level_names, high_level_names)[source]¶ Converts group names from a low level to high level API
This is useful for example when you want to return
db.groups()for thebob.bio.base. Your instance of the database should already havelow_level_namesandhigh_level_namesinitialized.
-
convert_names_to_lowlevel(names, low_level_names, high_level_names)[source]¶ Same as convert_names_to_highlevel but on reverse
-
file_names(files, directory, extension) → paths[source]¶ Returns the full path of the given File objects.
Parameters:
- files : [
- 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.
bob.db.base.File]Returns:
- paths : [str]
- The paths extracted for the files, in the same order.
-
files(ids, preserve_order=True)¶ Returns a list of
Fileobjects with the given file idsParameters: - ids – list, tuple 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.Return type:
-
get_client_id_from_model_id(model_id, **kwargs)[source]¶ Returns the client_id attached to the given model_id
Keyword Parameters:
- model_id
- The model_id to consider
Returns: The client_id attached to the given model_id
-
is_valid()¶ Returns if a valid session has been opened for reading the database.
-
model_ids(protocol=None, groups=None)[source]¶ Returns a set of models ids for the specific query by the user.
Keyword Parameters:
- protocol
- Ignored since the models are identical for all protocols.
- groups
- The groups to which the subjects attached to the models belong
Returns: A list containing all the models ids which have the given properties.
-
models(protocol=None, groups=None)[source]¶ Returns a set of models for the specific query by the user.
Keyword Parameters:
- protocol
- Ignored since the models are identical for all protocols.
groups
Returns: A list containing all the models which have the given properties.
-
objects(protocol=None, purposes=None, model_ids=None, groups=None)[source]¶ Returns a set of Files for the specific query by the user.
Keyword Parameters:
- protocol
- One of the protocols (‘pure_casia’, ‘lfw_fold1’, ‘lfw_fold2’, ‘lfw_fold3’, ‘lfw_fold4’, ‘lfw_fold5’,
- ‘lfw_fold6’, ‘lfw_fold7’, ‘lfw_fold8’, ‘lfw_fold9’, ‘lfw_fold10’).
- purposes
- The purposes required to be retrieved (‘enroll’, ‘probe’, ‘train’) 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” group.
- model_ids
- 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
- One of the groups (‘dev’, ‘eval’, ‘world’) 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.
Returns: A list of files which have the given properties.
-
original_file_name(file)[source]¶ This function returns the original file name for the given File object.
Keyword parameters:
- file :
- The File objects for which the file name should be retrieved
- Return value : str
- The original file name for the given File object
bob.bio.base.database.BioFileor a derivative
-
original_file_names(files) → paths[source]¶ Returns the full path of the original data of the given File objects.
Parameters:
- files : [
- The list of file object to retrieve the original data file names for.
bob.db.base.File]Returns:
- paths : [str]
- The paths extracted for the files, in the same order.
-
paths(ids, prefix=None, suffix=None, preserve_order=True)¶ Returns a full file paths considering particular file ids
Parameters: - ids – list, tuple 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.
Return type:
-
query(*args)¶ Creates a query to the database using the given arguments.
-
reverse(paths, preserve_order=True)¶ Reverses the lookup from certain paths, returns a list of
File‘sParameters: - 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).
Return type:
-
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 : [
- The list of files to be uniquified and sorted.
bob.bio.base.database.BioFile]Returns:
- sorted : [
- The sorted list of files, with duplicate BioFile.ids being removed.
bob.bio.base.database.BioFile]
-
uniquify(file_list)¶ Sorts the given list of File objects and removes duplicates from it.
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.
Return type: list - A sorted copy of the given
-
-
class
bob.db.casia_webface.File(id_file, client_id, path)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base,bob.db.base.FileGeneric file container
-
client_id¶
-
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.jpgor.hdf5.
Returns a string containing the newly generated file path.
-
metadata= MetaData(bind=None)¶
-
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.
-