Python API
The Replay-Attack Database accessors for Bob
-
bob.db.replay.get_config()[source]
Returns a string containing the configuration information.
-
class bob.db.replay.Attack(file, attack_support, attack_device, sample_type, sample_device)
Bases: sqlalchemy.ext.declarative.api.Base
Defines Spoofing Attacks (illicit attempts to authenticate)
-
attack_device
-
attack_device_choices = ('print', 'mobile', 'highdef', 'mask')
-
attack_support
-
attack_support_choices = ('fixed', 'hand')
-
file
-
file_id
-
id
-
metadata = MetaData(bind=None)
-
protocols
-
sample_device
-
sample_device_choices = ('mobile', 'highdef')
-
sample_type
-
sample_type_choices = ('video', 'photo')
-
class bob.db.replay.Client(id, set)
Bases: sqlalchemy.ext.declarative.api.Base
Database clients, marked by an integer identifier and the set they belong
to
-
id
-
metadata = MetaData(bind=None)
-
set
-
set_choices = ('train', 'devel', 'test')
-
class bob.db.replay.Database
Bases: object
The 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.
-
assert_validity()
Raise a RuntimeError if the database backend is not available
-
attack_devices()
Returns attack devices available in the database
-
attack_sample_types()
Returns attack sample types available in the database
-
attack_sampling_devices()
Returns sampling devices available in the database
-
attack_supports()
Returns attack supports available in the database
-
clients()
Returns an iterable with all known clients
-
connect()
Tries connecting or re-connecting to the database
-
files(directory=None, extension=None, **object_query)
Returns a set of filenames for the specific query by the user.
Deprecated since version 1.1.0: This function is deprecated, use Database.objects() instead.
Keyword Parameters:
- directory
- A directory name that will be prepended to the final filepath returned
- extension
- A filename extension that will be appended to the final filepath returned
- object_query
- All remaining arguments are passed to Database.objects()
untouched. Please check the documentation for such method for more
details.
Returns: A dictionary containing the resolved filenames considering all
the filtering criteria. The keys of the dictionary are unique identities
for each file in the replay attack database. Conserve these numbers if you
wish to save processing results later on.
-
groups()
Returns the names of all registered groups
-
has_client_id(id)
Returns True if we have a client with a certain integer identifier
-
has_protocol(name)
Tells if a certain protocol is available
-
is_valid()
Returns if a valid session has been opened for reading the database
-
lights()
Returns light variations available in the database
-
objects(support=('fixed', 'hand'), protocol='grandtest', groups=('train', 'devel', 'test'), cls=('attack', 'real'), light=('controlled', 'adverse'), clients=None)
Returns a list of unique File objects for the specific
query by the user.
Keyword parameters:
- support
- One of the valid support types as returned by attack_supports() or all,
as a tuple. If you set this parameter to an empty string or the value
None, we use reset it to the default, which is to get all.
- protocol
- The protocol for the attack. One of the ones returned by protocols(). If
you set this parameter to an empty string or the value None, we use reset
it to the default, “grandtest”.
- groups
- One of the protocolar subgroups of data as returned by groups() or a
tuple with several of them. If you set this parameter to an empty string
or the value None, we use reset it to the default which is to get all.
- cls
- Either “attack”, “real”, “enroll” or any combination of those (in a
tuple). Defines the class of data to be retrieved. If you set this
parameter to an empty string or the value None, we use reset it to the
default, (“real”, “attack”).
- light
- One of the lighting conditions as returned by lights() or a combination
of the two (in a tuple), which is also the default.
- clients
- If set, should be a single integer or a list of integers that define the
client identifiers from which files should be retrieved. If ommited, set
to None or an empty list, then data from all clients is retrieved.
Returns: A list of File objects.
-
paths(ids, prefix='', suffix='')
Returns a full file paths considering particular file ids, a given
directory and an extension
Keyword Parameters:
- id
- The ids of the object in the database table “file”. This object should be
a python iterable (such as a tuple or list).
- prefix
- The bit of path to be prepended to the filename stem
- suffix
- The extension determines the suffix that will be appended to the filename
stem.
Returns a list (that may be empty) of the fully constructed paths given the
file ids.
-
protocol(name)
Returns the protocol object in the database given a certain name. Raises
an error if that does not exist.
-
protocols()
Returns all protocol objects.
-
reverse(paths)
Reverses the lookup: from certain stems, returning file ids
Keyword Parameters:
- paths
- The filename stems I’ll query for. This object should be a python
iterable (such as a tuple or list)
Returns a list (that may be empty).
-
save(data, directory, extension)
This method takes a dictionary of blitz arrays or bob.database.Array’s
and saves the data respecting the original arrangement as returned by
files().
Deprecated since version 1.1.0: This function is deprecated, use File.save() instead.
Keyword Parameters:
- data
- A dictionary with two keys ‘real’ and ‘attack’, each containing a
dictionary mapping file ids from the original database to an object that
supports the bob “save()” protocol.
- directory
- This is the base directory to which you want to save the data. The
directory is tested for existence and created if it is not there with
os.makedirs()
- extension
- The extension determines the way each of the arrays will be saved.
-
save_one(id, obj, directory, extension)
Saves a single object supporting the bob save() protocol.
Deprecated since version 1.1.0: This function is deprecated, use File.save() instead.
This method will call save() on the the given object using the correct
database filename stem for the given id.
Keyword Parameters:
- id
- The id of the object in the database table “file”.
- obj
- The object that needs to be saved, respecting the bob save() protocol.
- directory
- This is the base directory to which you want to save the data. The
directory is tested for existence and created if it is not there with
os.makedirs()
- extension
- The extension determines the way each of the arrays will be saved.
-
class bob.db.replay.File(client, path, light)
Bases: sqlalchemy.ext.declarative.api.Base
Generic file container
-
bbx(directory=None)
Reads the file containing the face locations for the frames in the
current video
Keyword parameters:
- directory
- A directory name that will be prepended to the final filepaths where the
face bounding boxes are located, if not on the current directory.
- Returns:
A numpy.ndarray containing information about the located
faces in the videos. Each row of the numpy.ndarray
corresponds for one frame. The five columns of the
numpy.ndarray are (all integers):
- Frame number (int)
- Bounding box top-left X coordinate (int)
- Bounding box top-left Y coordinate (int)
- Bounding box width (int)
- Bounding box height (int)
Note that not all the frames may contain detected faces.
-
client
-
client_id
-
facefile(directory=None)
Returns the path to the companion face bounding-box file
Keyword parameters:
- directory
- An optional directory name that will be prefixed to the returned result.
Returns a string containing the face file path.
-
get_attack()
Returns the attack object equivalent to this file or raise
-
get_realaccess()
Returns the real-access object equivalent to this file or raise
-
id
-
is_real()
Returns True if this file belongs to a real access, False otherwise
-
light
-
light_choices = ('controlled', 'adverse')
-
load(directory=None, extension='.hdf5')
Loads the data at the specified location and using the given extension.
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.
-
metadata = MetaData(bind=None)
-
path
-
save(data, directory=None, extension='.hdf5')
Saves the input data at the specified location and using the given
extension.
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.
-
videofile(directory=None)
Returns the path to the database video file for this object
Keyword parameters:
- directory
- An optional directory name that will be prefixed to the returned result.
Returns a string containing the video file path.
-
class bob.db.replay.Protocol(name)
Bases: sqlalchemy.ext.declarative.api.Base
Replay attack protocol
-
id
-
metadata = MetaData(bind=None)
-
name
-
class bob.db.replay.RealAccess(file, purpose, take)
Bases: sqlalchemy.ext.declarative.api.Base
Defines Real-Accesses (licit attempts to authenticate)
-
file
-
file_id
-
id
-
metadata = MetaData(bind=None)
-
protocols
-
purpose
-
purpose_choices = ('authenticate', 'enroll')
-
take