bob.pad set of modules are specifically designed to be as flexible as possible while trying to keep things simple.
Therefore, python is used to implement tools such as preprocessors, feature extractors and the PAD algorithms.
Everything is file based so any tool can implement its own way of reading and writing data, features or models.
Configurations are stored in configuration files, so it should be easy to test different parameters of your algorithms without modifying the code.
Also, it is important to note that
bob.pad.base reuses concept, design, and large parts of code from bob.bio.base package,
which is designed for recognition experiments.
Most of the functionality is provided in the base classes, but any function can be overridden in the derived class implementations.
In the derived class constructors, the base class constructor needs to be called.
For automatically tracing the algorithms, all parameters that are passed to the derived class constructor should be passed to the base class constructor as a list of keyword arguments (which is indicated by
This will assure that all parameters of the experiments are stored into the
All tools are based on reading, processing and writing files.
By default, any type of file is allowed to be handled, and file names are provided to the
write_... functions as strings.
If you plan to write your own tools, please assure that you are following the following structure.
Preprocessors and Extractors¶
All preprocessor and extractor classes are based on the empty base classess implemented in bob.bio.base, specifically,
All presentation attack detection algorithms are derived from the
The constructor of this class has the following options, which are selected according to the current algorithm:
performs_projection: If set to
True, features will be projected using the
projectfunction. With the default
projectfunction will not be called at all.
performs_projectionis enabled, this flag specifies if the projector needs training. If
True(the default), the
train_projectorfunction will be called.
A presentation attack detection algorithm has to override at least two functions:
__init__(self, <parameters>): Initializes the face recognition algorithm with the parameters it needs. Calls the base class constructor, e.g. as
bob.pad.base.algorithm.Algorithm.__init__(self, ...)(there are more parameters to this constructor, see above).
score(self, toscore) -> value: Computes score given the projected value returned by the classifier.
Additionally, an algorithm may need to project the features before they can be used in spoofing detection. In this case, (some of) the function(s) are overridden:
train_projector(self, train_features, projector_file): Uses the given list of features and writes the
If you write this function, please assure that you use both
requires_projector_training=True(for the latter, this is the default, but not for the former) during the base class constructor call in your
__init__function. Please also assure that you overload the
load_projector(self, projector_file): Loads the projector from the given file, i.e., as stored by
train_projector. This function is always called before the
scorefunctions are executed.
project(self, feature) -> feature: Projects the given feature and returns the projected feature, which should either be a
numpy.ndarrayor an instance of a class that defines a
If you write this function, please assure that you use
performs_projection=Trueduring the base class constructor call in your
And once more, if the projected feature is not of type
numpy.ndarray, the following methods are overridden:
write_feature(feature, feature_file): Writes the feature (as returned by the
projectfunction) to file.
read_feature(feature_file) -> feature: Reads and returns the feature (as written by the
By default, it is assumed that features are of type
bob.pad.base.algorithm.Algorithm class provides default implementation for the case that several scores (or features) are used for one sample:
score_for_multiple_projections(self, toscore): In case your object store several features or scores, call this function to compute the average (or min, max, …) of the scores.
This package includes a script bob pad metrics, that can be used to compute the PAD metrics APCER and BPCER as defined in the ISO/IEC 30107 part3 standard. To learn more about it run:
$ bob pad metrics --help
Example implementations of the base classes can be found in all of the
Here is the current list of implementations:
complete this list, once the other packages are documented as well.
Databases provide information about the data sets, on which the PAD algorithm should run on.
Particularly, databases come with one or more evaluation protocols, which defines, which part of the
data should be used for training, algorithm tuning, and testing.
Some protocols split up the data into three different groups: a training set (aka
train group), a
development set (aka
dev group) and an evaluation set (aka
eval, sometimes also referred as test set).
Anti-spoofing Database Interface¶
For most of the data sets, we rely on the database interfaces from Bob.
Particularly, all databases that are derived from the
bob.pad.base.database.PadDatabase (click here for a list of implemented databases) are supported.
Defining your own Database¶
If you want to define you own database, you are welcome to write your own database wrapper class.
In this case, you have to derive your class from the
and provide only the following functions:
__init__(self, <your-parameters>, **kwargs): Constructor of your database interface. Please call the base class constructor, providing all the required parameters, e.g. by
objects(self, , groups=None, protocol=None, purposes=None, model_ids=None, **kwargs): Expected to return a list of
bob.pad.base.database.PadFileobjects of the database given the specified parameters. The list needs to be sorted by the file id (you can use the
self.sort(files)function for sorting).
training_files(self, step, arrange_by_client = False): A sorted list of the
bob.bio.base.database.BioFileobjects that is used for training. You should have
One important aspect of the
bob.pad packages is reproducibility.
To be able to reproduce an experiment, it is required that all parameters of all tools are present.
bob.pad (similarly to
bob.bio) this is achieved by providing these parameters in configuration files.
In these files, an instance of one of the tools is generated, and assigned to a variable with a specific name.
These variable names are:
databasefor an instance of a (derivation of a)
preprocessorfor an instance of a (derivation of a)
extractorfor an instance of a (derivation of a)
algorithmfor an instance of a (derivation of a)
gridfor an instance of the
Finally, some of the configuration files, which sit in the
bob/pad/*/config directories, are registered as resources.
This means that a resource is nothing else than a short name for a registered instance of one of the tools (database, preprocessor, extractor, algorithm or grid configuration) of
bob.pad, which has a pre-defined set of parameters.
The process of registering a resource is relatively easy.
We use the SetupTools mechanism of registering so-called entry points in the
setup.py file of the according
Particularly, we use a specific list of entry points, which are:
bob.pad.base.database.PadDatabaseto register an instance of a (derivation of a)
bob.bio.preprocessorto register an instance of a (derivation of a)
bob.bio.extractorto register an instance of a (derivation of a)
bob.pad.algorithmto register an instance of a (derivation of a)
bob.bio.gridto register an instance of the
For each of the tools, several resources are defined, which you can list with the
./bin/resources.py command line.
When you want to register your own resource, make sure that your configuration file is importable (usually it is sufficient to have an empty
__init__.py file in the same directory as your configuration file).
Then, you can simply add a line inside the according
entry_points section of the
setup.py file (you might need to create that section, just follow the example of the
setup.py file that you can find online in the base directory of our bob.pad.base GitHub page).
./bin/buildout, your new resource should be listed in the output of