Tools implemented in bob.pad.base

Please not that some parts of the code in this package are dependent on and reused from package.


Base Classes

Most of the base classes are reused from Only one base class that is presentation attack detection specific, Algorithm is implemented in this package.



Base class for Vanilla PAD pipeline


Wraps a bob.pad.base database and generates conforming samples

bob.pad.base.database.PadDatabase(name[, ...])

This class represents the basic API for database access.

bob.pad.base.database.PadFile(client_id, path)

A simple base class that defines basic properties of File object for the use in PAD experiments

Preprocessors and Extractors

Preprocessors and Extractors from the package can also be used in this package.


class bob.pad.base.database.FileListPadDatabase(dataset_protocols_path, protocol, transformer=None, **kwargs)

Bases: bob.pad.base.pipelines.vanilla_pad.Database, bob.pipelines.datasets.FileListDatabase

A PAD database interface from CSV files.


Returns Sample’s to train a PAD model


samples – List of samples for model training.

Return type



Returns Sample’s to be scored.


group (str, optional) – Limits samples to this group


samples – List of samples to be scored.

Return type


samples(groups=None, purposes=None)[source]

Get samples of a certain group


groups (str, optional) – A str or list of str to be used for filtering samples, by default None


A list containing the samples loaded from csv files.

Return type


class bob.pad.base.database.HighBioDatabase(filelists_directory=None, original_directory='[DB_DATA_DIRECTORY]', original_extension='.wav', db_name='', file_class=None, **kwargs)


Implements verification API for querying High database.


Reads the annotations for the given file id from file and returns them in a dictionary.


file (BioFile) – The BioFile object for which the annotations should be read.


The annotations as a dictionary, e.g.: {'reye':(re_y,re_x), 'leye':(le_y,le_x)}

Return type


arrange_by_client(files) files_by_client[source]

Arranges the given list of files by client id. This function returns a list of lists of File’s.


A list of files that should be split up by BioFile.client_id.



The list of lists of files, where each sub-list groups the files with the same BioFile.client_id

client_id_from_model_id(model_id, group='dev')[source]

This wrapper around PAD database does not have a knowledge of model ids used in verification experiments, so we just assume that the client_id is the same as model_id, which is actually true for most of the verification databases as well.

model_ids_with_protocol(groups=None, protocol=None, **kwargs)[source]

This wrapper around PAD database does not have a knowledge of model ids used in verification experiments, so we just assume that the model_ids are the same as client ids, which is actually true for most of the verification databases as well.

objects(protocol=None, purposes=None, model_ids=None, groups=None, **kwargs)[source]

Maps objects method of PAD databases into objects method of Verification database

  • protocol (str) – To distinguish two vulnerability scenarios, protocol name should have either ‘-licit’ or ‘-spoof’ appended to it. For instance, if DB has protocol ‘general’, the named passed to this method should be ‘general-licit’, if we want to run verification experiments on bona fide data only, but it should be ‘general-spoof’, if we want to run it for spoof scenario (the probes are attacks).

  • purposes ([str]) – This parameter is passed by the verification experiment

  • model_ids ([object]) – This parameter is passed by the verification experiment

  • groups ([str]) – We map the groups from (‘world’, ‘dev’, ‘eval’) used in verification experiments to (‘train’, ‘dev’, ‘eval’)

  • **kwargs – The rest of the parameters valid for a given database


Set of BioFiles that verification experiments expect.

Return type


class bob.pad.base.database.HighPadDatabase(filelists_directory=None, original_directory='[DB_DATA_DIRECTORY]', original_extension='.wav', file_class=None, db_name='', **kwargs)

Bases: bob.pad.base.database.FileListPadDatabase

class bob.pad.base.database.PadDatabase(name, protocol='Default', original_directory=None, original_extension=None, **kwargs)


This class represents the basic API for database access. Please use this class as a base class for your database access classes. Do not forget to call the constructor of this base class in your derived class.


name : str A unique name for the database.

protocol : str or None The name of the protocol that defines the default experimental setup for this database.

original_directory : str The directory where the original data of the database are stored.

original_extension : str The file name extension of the original data.

kwargs : key=value pairs The arguments of the base class constructor.

all_files(groups=('train', 'dev', 'eval'), flat=False)[source]

Returns all files of the database, respecting the current protocol. The files can be limited using the all_files_options in the constructor.

  • groups (str or tuple or None) – The groups to get the data for. it should be some of ('train', 'dev', 'eval') or None

  • flat (bool) – if True, it will merge the real and attack files into one list.


files – The sorted and unique list of all files of the database.

Return type



Returns the annotations for the given File object, if available. You need to override this method in your high-level implementation. If your database does not have annotations, it should return None.



The file for which annotations should be returned.


annotsdict or None

The annotations for the file, if available.

model_ids_with_protocol(groups=None, protocol=None, **kwargs) ids[source]

Client-based PAD is not implemented.

abstract objects(groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)[source]

This function returns lists of File objects, which fulfill the given restrictions.

Keyword parameters:

groupsstr or [str]

The groups of which the clients should be returned. Usually, groups are one or more elements of (‘train’, ‘dev’, ‘eval’)


The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

purposesstr or [str]

The purposes for which File objects should be retrieved. Usually it is either ‘real’ or ‘attack’.

model_ids[various type]

This parameter is not supported in PAD databases yet

original_file_names(files) paths[source]

Returns the full paths of the real and attack data of the given PadFile objects.


files[[bob.pad.base.database.PadFile], [bob.pad.base.database.PadFile]

The list of lists ([real, attack]) of file object to retrieve the original data file names for.


paths[str] or [[str]]

The paths extracted for the concatenated real+attack files, in the preserved order.

training_files(step=None, arrange_by_client=False) files[source]

Returns all training File objects This function needs to be implemented in derived class implementations.


The parameters are not applicable in this version of anti-spoofing experiments


files[bob.pad.base.database.PadFile] or [[bob.pad.base.database.PadFile]]

The (arranged) list of files used for the training.

class bob.pad.base.database.PadFile(client_id, path, attack_type=None, file_id=None, original_directory=None, original_extension=None, annotation_directory=None, annotation_extension=None, annotation_type=None)


A simple base class that defines basic properties of File object for the use in PAD experiments

Grid Configuration

Code related to grid is reused from package. Please see the corresponding documentation.