Python API

The CASIA-FASD database is a spoofing attack database which consists of three types of attacks: warped printed photographs, printed photographs with cut eyes and video attacks. The samples are taken with three types of cameras: low quality, normal quality and high quality.

The actual raw data for the database should be downloaded from the original URL. This package only contains the Bob accessor methods to use the DB directly from python, with our certified protocols.

References

1. Z. Zhang, J. Yan, S. Lei, D. Yi, S. Z. Li: “A Face Antispoofing Database with Diverse Attacks”, In proceedings of the 5th IAPR International Conference on Biometrics (ICB’12), New Delhi, India, 2012.

class bob.db.casia_fasd.Database(foldsdir=None)[source]

Bases: object

set_foldsdir(foldsdir)[source]

Sets the directory holding the cross validation protocol of the database

check_validity(l, obj, valid, default)[source]

Checks validity of user input data against a set of valid values

get_file(pc)[source]

Returns the full file path given the path components pc

files(directory=None, extension=None, ids=[], groups=None, cls=None, qualities=None, types=None)[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

ids

The id of the client whose videos need to be retrieved. Should be an integer number in the range 1-50 (the total number of client is 50

groups

One of the protocolar subgroups of data as specified in the tuple 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” or a 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, it will be set to the tuple (“real”, “attack”).

qualities

Either “low”, “normal” or “high” or any combination of those (in a tuple). Defines the qualities of the videos in the database that are going to be used. If you set this parameter to the value None, the videos of all qualities are returned (“low”, “normal”, “high”).

types

Either “warped”, “cut” or “video” or any combination of those (in a tuple). Defines the types of attack videos in the database that are going to be used. If you set this parameter to the value None, the videos of all the attack types are returned (“warped”, “cut”, “video”).

Returns: A dictionary containing the resolved filenames considering all the filtering criteria. The keys of the dictionary are just pro-forma (for uniformity with the other databases).

objects(ids=[], groups=None, cls=None, qualities=None, types=None)[source]

Returns a list of unique File objects for the specific query by the user.

Keyword Parameters:

ids

The id of the client whose videos need to be retrieved. Should be an integer number in the range 1-50 (the total number of client is 50

groups

One of the protocolar subgroups of data as specified in the tuple 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” or a 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, it will be set to the tuple (“real”, “attack”).

qualities

Either “low”, “normal” or “high” or any combination of those (in a tuple). Defines the qualities of the videos in the database that are going to be used. If you set this parameter to the value None, the videos of all qualities are returned (“low”, “normal”, “high”).

types

Either “warped”, “cut” or “video” or any combination of those (in a tuple). Defines the types of attack videos in the database that are going to be used. If you set this parameter to the value None, the videos of all the attack types are returned (“warped”, “cut”, “video”).

Returns: A list of File objects.

cross_valid_gen(numpos, numneg, numfolds=10, outfilename=None)[source]

Performs N-fold cross-validation on a given number of samples. Generates the indices of the validation subset for N folds, and writes them into a text file (the indices of the training samples are easy to compute once the indices of the validation subset are known). This method is intended for 2-class classification problems, therefore the number of both positive and negative samples should be given at the beginning. The method generates validation indices for both positive and negative samples separately. Each row of the output file are the validation indices of one fold; validation indices for the positive class are in the odd lines, and validation indices for the negative class are in the even lines.

Keyword parameters:

numpos

Number of positive samples

numneg

Number of negative samples

numfold

Number of folds

outfilename

The filename of the output file

cross_valid_read()[source]

Reads the cross-validation indices from a file and returns two lists of validation indices: for the positive and for the negative class. Each list actually consists of sublists; one sublist with validation indices for each fold.

Keyword parameters:

cross_valid_foldfiles(cls, types=None, fold_no=0, directory=None, extension=None)[source]

Returns two dictionaries: one with the names of the files of the validation subset in one fold, and one with the names of the files in the training subset of that fold. The number of the cross_validation fold is given as a parameter.

Deprecated since version 1.1.0: This function is deprecated, use Database.objects() instead.

Keyword parameters:

cls

The class of the samples: ‘real’ or ‘attack’

types

Type of the database that is going to be used: ‘warped’, ‘cut’ or ‘video’ or a tuple of these

fold_no

Number of the fold

directory

This parameter will be prepended to all the filenames which are going to be returned by this procedure

extension

This parameter will be appended to all the filenames which are going to be returned by this procedure

cross_valid_foldobjects(cls, types=None, qualities=None, fold_no=0)[source]

Returns two dictionaries: one with the names of the files of the validation subset in one fold, and one with the names of the files in the training subset of that fold. The number of the cross_validation fold is given as a parameter.

Keyword parameters:

cls

The class of the samples: ‘real’ or ‘attack’

types

Type of the database that is going to be used: ‘warped’, ‘cut’ or ‘video’ or a tuple of these

qualities

Either “low”, “normal” or “high” or any combination of those (in a tuple). Defines the qualities of the videos in the database that are going to be used. If you set this parameter to the value None, the videos of all qualities are returned (“low”, “normal”, “high”).

fold_no

Number of the fold

save_by_filename(filename, 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 filename

Keyword Parameters:

filename

The unique filename under which the object will be saved. Before calling this method, the method files() should be called (with no directory and extension arguments passed) in order to obtain the unique filenames for each of the files to be saved.

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.casia_fasd.File(filename, cls, group)[source]

Bases: object

Generic file container

get_file(pc)[source]

Returns the full file path given the path components pc

make_path(directory=None, extension=None)[source]

Wraps this files’ filename 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.

is_real()[source]

True if the file belongs to a real access, False otherwise

get_clientid()[source]

The ID of the client. Value from 1 to 50. Clients in the train and devel set may have IDs from 1 to 20; clients in the test set have IDs from 21 to 50.

get_type()[source]

The type of attack, if it is an attack. Possible values: ‘warped’, ‘cut’ and ‘video’. Returns None for real accesses

get_quality()[source]

The quality of the video file. Possible value: ‘normal’, ‘low’ and ‘high’.

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.

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.

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 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.

load(directory=None, extension='.hdf5')[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.

save(data, directory=None, extension='.hdf5')[source]

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

If not empty or None, this directory is prefixed to the final file destination

extension

The extension of the filename - this will control the type of output and the codec for saving the input blob.

bob.db.casia_fasd.get_config()[source]

Returns a string containing the configuration information.