Python API for bob.pad.base¶
Summary¶
Databases¶
Base database class for PAD experiments. |
|
A PAD database interface from CSV files. |
Score Functions¶
|
Loads PAD scores from a CSV score file, splits them by attack vs bonafide. |
Returns scores for Bona-Fide samples and scores for each PAI. |
|
Calculates the threshold based on the given method. |
|
Computes the threshold given the desired APCER as the criteria. |
|
Computes APCER_PAI, APCER, and BPCER given the positive scores and a list of negative scores and a threshold. |
Details¶
- class bob.pad.base.pipelines.Database¶
Bases:
object
Base database class for PAD experiments.
- abstract fit_samples()[source]¶
Returns
bob.pipelines.Sample
’s to train a PAD model.- Returns
samples – List of samples for model training.
- Return type
- abstract predict_samples(group='dev')[source]¶
Returns
bob.pipelines.Sample
’s to be scored.
- class bob.pad.base.database.FileListPadDatabase(dataset_protocols_path, protocol, transformer=None, **kwargs)¶
Bases:
bob.pad.base.pipelines.Database
,bob.pipelines.FileListDatabase
A PAD database interface from CSV files.
- fit_samples()[source]¶
Returns
bob.pipelines.Sample
’s to train a PAD model.- Returns
samples – List of samples for model training.
- Return type
- predict_samples(group='dev')[source]¶
Returns
bob.pipelines.Sample
’s to be scored.
Utility functions for computation of EPSC curve and related measurement
- bob.pad.base.error_utils.calc_threshold(method, pos, negs, all_negs, far_value=None, is_sorted=False)[source]¶
Calculates the threshold based on the given method.
- Parameters
method (str) – One of
bpcer20
,eer
,min-hter
,apcer20
.pos (
array_like
) – The positive scores. They should be sorted!negs (list) – A list of array_like negative scores. Each item in the list corresponds to scores of one PAI.
all_negs (
array_like
) – An array of all negative scores. This can be calculated from negs as well but we ask for it since you might have it already calculated.far_value (
float
, optional) – If method is far, far_value and all_negs are used to calculate the threshold.is_sorted (
bool
, optional) – If True, it means all scores are sorted and no sorting will happen.
- Returns
The calculated threshold.
- Return type
- Raises
ValueError – If method is unknown.
- bob.pad.base.error_utils.apcer_threshold(desired_apcer, pos, *negs, is_sorted=False)[source]¶
Computes the threshold given the desired APCER as the criteria.
APCER is computed as max of all APCER_PAI values. The threshold will be computed such that the real APCER is at most the desired value.
- Parameters
- Returns
The computed threshold that satisfies the desired APCER.
- Return type
- bob.pad.base.error_utils.apcer_bpcer(threshold, pos, *negs)[source]¶
Computes APCER_PAI, APCER, and BPCER given the positive scores and a list of negative scores and a threshold.
- Parameters
- Returns
A tuple such as (list of APCER_PAI, APCER, BPCER)
- Return type
- bob.pad.base.error_utils.split_csv_pad_per_pai(filename, regexps=[], regexp_column='attack_type')[source]¶
Returns scores for Bona-Fide samples and scores for each PAI. By default, the real_id column (second column) is used as indication for each Presentation Attack Instrument (PAI).
For example, with default regexps and regexp_column, if you have scores like:
claimed_id, test_label, is_bonafide, attack_type, score 001, bona_fide_sample_1_path, True, , 0.9 001, print_sample_1_path, False, print, 0.6 001, print_sample_2_path, False, print, 0.6 001, replay_sample_1_path, False, replay, 0.2 001, replay_sample_2_path, False, replay, 0.2 001, mask_sample_1_path, False, mask, 0.5 001, mask_sample_2_path, False, mask, 0.5
this function will return 1 set of positive scores, and 3 sets of negative scores (for each print, replay, and mask PAIs).
Otherwise, you can provide a list regular expressions that match each PAI. For example, with regexps as [‘print’, ‘replay’, ‘mask’], if you have scores like:
claimed_id, test_label, is_bonafide, attack_type, score 001, bona_fide_sample_1_path, True, , 0.9 001, print_sample_1_path, False, print/1, 0.6 001, print_sample_2_path, False, print/2, 0.6 001, replay_sample_1_path, False, replay/1, 0.2 001, replay_sample_2_path, False, replay/2, 0.2 001, mask_sample_1_path, False, mask/1, 0.5 001, mask_sample_2_path, False, mask/2, 0.5
the function will return 3 sets of negative scores (for print, replay, and mask PAIs, given in regexp).
- Parameters
filename (str) – Path to the score file.
regexps (
list
, optional) – A list of regular expressions that match each PAI. If not given, the values in the column pointed by regexp_column are used to find scores for different PAIs.regexp_column (
str
, optional) – If a list of regular expressions are given, those patterns will be matched against the values in this column. default:attack_type
- Returns
A tuple, ([positives], {‘pai_name’: [negatives]}), containing positive scores and a dict of negative scores mapping PAIs names to their respective scores.
- Return type
- Raises
ValueError – If none of the given regular expressions match the values in regexp_column.
KeyError – If regexp_column is not a column of the CSV file.