Python API¶
The Replay-Attack Database accessors for Bob
-
class
bob.db.replay.
Attack
(file, attack_support, attack_device, sample_type, sample_device)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
Defines Spoofing Attacks (illicit attempts to authenticate)
-
attack_support_choices
= ('fixed', 'hand')¶ Types of attack support
-
attack_device_choices
= ('print', 'mobile', 'highdef', 'mask')¶ Types of devices used for spoofing
-
sample_type_choices
= ('video', 'photo')¶ Original sample type
-
sample_device_choices
= ('mobile', 'highdef')¶ Original sample device
-
id
¶ Unique identifier for this attack
-
file_id
¶ The file identifier this attack is linked to
-
protocols
¶ A direct link to the protocols this file is linked to
-
attack_support
¶ The attack support
-
attack_device
¶ The attack device
-
sample_type
¶ The attack sample type
-
sample_device
¶ The attack sample device
-
-
class
bob.db.replay.
Client
(id, set)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
Database clients, marked by an integer identifier and the set they belong to
-
set_choices
= ('train', 'devel', 'test')¶ Possible groups to which clients may belong to
-
id
¶ Key identifier for clients
-
set
¶ Set to which this client belongs to
-
-
class
bob.db.replay.
Database
(original_directory=None, original_extension=None, **kwargs)[source]¶ Bases:
bob.db.base.SQLiteDatabase
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.
-
objects
(support='fixed', 'hand', protocol='grandtest', groups='train', 'devel', 'test', cls='attack', 'real', light='controlled', 'adverse', clients=None)[source]¶ 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.
-
files
(directory=None, extension=None, **object_query)[source]¶ 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.
-
protocol
(name)[source]¶ Returns the protocol object in the database given a certain name. Raises an error if that does not exist.
-
paths
(ids, prefix='', suffix='')[source]¶ 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.
-
reverse
(paths)[source]¶ 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_one
(id, obj, directory, extension)[source]¶ 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.
-
save
(data, directory, extension)[source]¶ 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.
-
-
class
bob.db.replay.
File
(client, path, light)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
,bob.db.base.File
Generic file container
-
light_choices
= ('controlled', 'adverse')¶ List of illumination conditions for data taking
-
id
¶ Key identifier for files
-
client_id
¶ The client identifier to which this file is bound to
-
client
¶ A direct link to the client object that this file belongs to
-
path
¶ The (unique) path to this file inside the database
-
light
¶ The illumination condition in which the data for this file was taken
-
videofile
(directory=None)[source]¶ 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.
-
facefile
(directory=None)[source]¶ 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.
-
bbx
(directory=None)[source]¶ 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 thenumpy.ndarray
corresponds for one frame. The five columns of thenumpy.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.
-
load
(directory=None, extension=None)[source]¶ 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.
-
-
class
bob.db.replay.
Protocol
(name)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
Replay attack protocol
-
id
¶ Unique identifier for the protocol (integer)
-
name
¶ Protocol name
-
-
class
bob.db.replay.
RealAccess
(file, purpose, take)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
Defines Real-Accesses (licit attempts to authenticate)
-
purpose_choices
= ('authenticate', 'enroll')¶ Types of purpose for this video
-
id
¶ Unique identifier for this real-access object
-
file_id
¶ The file identifier the current real-access is bound to
-
protocols
¶ A direct link to the protocols this file is linked to
-
purpose
¶ The purpose of this video
-
take
¶ Take number
-