Python API

This section includes information for using the Python API of bob.fusion.base.

Summary

Algorithms

bob.fusion.base.algorithm.Algorithm([...])

A class to be used in score fusion

bob.fusion.base.algorithm.AlgorithmBob([...])

A class to be used in score fusion using bob machines.

bob.fusion.base.algorithm.Weighted_Sum([weights])

weighted sum (default: mean)

bob.fusion.base.algorithm.GMM([...])

GMM Score fusion

Preprocessors

bob.fusion.base.preprocessor.Tanh([copy])

A tanh feature scaler:

bob.fusion.base.preprocessor.ZNorm([copy])

ZNorm feature scaler This scaler works just like sklearn.preprocessing.StandardScaler but only takes the zero effort impostors into account when estimating the mean and standard deviation.

Fusion Algorithms

class bob.fusion.base.algorithm.Algorithm(preprocessors=None, classifier=None, **kwargs)

Bases: object

A class to be used in score fusion

classifier
preprocessors
str

A dictionary that its content will printed in the __str__ method.

Type

dict

__init__(preprocessors=None, classifier=None, **kwargs)[source]
Parameters
fuse(scores)[source]
scores: numpy.ndarray

A numpy.ndarray with the shape of (n_samples, n_systems).

Returns:

fused_score: numpy.ndarray

The fused scores in shape of (n_samples,).

load(model_file)[source]

Load the algorithm the same way it was saved. A new instance will be returned.

Returns:

loaded_algorithm: Algorithm

A new instance of the loaded algorithm.

preprocess(scores)[source]

scores: numpy.ndarray with the shape of (n_samples, n_systems). returns the transformed scores.

save(model_file)[source]

Save the instance of the algorithm.

model_file: str

A path to save the file. Please note that file objects are not accepted. The filename MUST end with “.pkl”. Also, an algorithm may save itself in multiple files with different extensions such as model_file and model_file[:-3]+’hdf5’.

train(train_neg, train_pos, devel_neg=None, devel_pos=None)[source]

If you use development data for training you need to override this method.

train_neg: numpy.ndarray

Negatives training data should be numpy.ndarray with the shape of (n_samples, n_systems).

train_pos: numpy.ndarray

Positives training data should be numpy.ndarray with the shape of (n_samples, n_systems).

devel_neg, devel_pos: numpy.ndarray

Same as train but used for development (validation).

train_preprocessors(X, y=None)[source]

Train preprocessors in order. X: numpy.ndarray with the shape of (n_samples, n_systems).

class bob.fusion.base.algorithm.AlgorithmBob(preprocessors=None, classifier=None, **kwargs)

Bases: bob.fusion.base.algorithm.Algorithm

A class to be used in score fusion using bob machines.

custom_save(model_file)[source]
load(model_file)[source]

Load the algorithm the same way it was saved. A new instance will be returned.

Returns:

loaded_algorithm: Algorithm

A new instance of the loaded algorithm.

class bob.fusion.base.algorithm.Empty(**kwargs)

Bases: bob.fusion.base.algorithm.Algorithm

Empty algorithm This algorithm does not change scores by itself and only applies the preprocessors.

__init__(**kwargs)[source]
Parameters
decision_function(scores)[source]
fit(X, y)[source]
class bob.fusion.base.algorithm.GMM(number_of_gaussians=None, gmm_training_iterations=25, training_threshold=0.0005, variance_threshold=0.0005, update_weights=True, update_means=True, update_variances=True, init_seed=5489, **kwargs)

Bases: bob.fusion.base.algorithm.AlgorithmBob

GMM Score fusion

__init__(number_of_gaussians=None, gmm_training_iterations=25, training_threshold=0.0005, variance_threshold=0.0005, update_weights=True, update_means=True, update_variances=True, init_seed=5489, **kwargs)[source]
Parameters
decision_function(scores)[source]
train(train_neg, train_pos, devel_neg=None, devel_pos=None)[source]

If you use development data for training you need to override this method.

train_neg: numpy.ndarray

Negatives training data should be numpy.ndarray with the shape of (n_samples, n_systems).

train_pos: numpy.ndarray

Positives training data should be numpy.ndarray with the shape of (n_samples, n_systems).

devel_neg, devel_pos: numpy.ndarray

Same as train but used for development (validation).

class bob.fusion.base.algorithm.Weighted_Sum(weights=None, **kwargs)

Bases: bob.fusion.base.algorithm.Algorithm

weighted sum (default: mean)

__init__(weights=None, **kwargs)[source]
Parameters
decision_function(scores)[source]
fit(X, y)[source]

Fusion Preprocessors

class bob.fusion.base.preprocessor.Tanh(copy=True, **kwargs)

Bases: sklearn.preprocessing.StandardScaler

A tanh feature scaler:

\[0.5 \left( \tanh\left( 0.01 \cdot \frac{X - \mu}{\sigma}\right) + 1 \right)\]

This scaler is both efficient and is robust to outliers.

The original implementation in Hampel, Frank R., et al. "Robust statistics: the approach based on influence functions." (1986). uses an influence function but this is not used here.

__init__(copy=True, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(X, y=None)[source]

Estimates the mean and standard deviation of samples. Only positive samples are used in estimation.

inverse_transform(X, copy=None)[source]

Perform inverse scaling.

transform(X, copy=None)[source]

Perform scaling.

class bob.fusion.base.preprocessor.ZNorm(copy=True, **kwargs)

Bases: sklearn.preprocessing.StandardScaler

ZNorm feature scaler This scaler works just like sklearn.preprocessing.StandardScaler but only takes the zero effort impostors into account when estimating the mean and standard deviation. You should not use this scaler when PAD scores are present.

__init__(copy=True, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(X, y=None)[source]

Estimates the mean and standard deviation of samples. Only positive samples are used in estimation.

Fusion Scripts

bob.fusion.base.script.routine_fusion(algorithm, model_file, scores_train_lines, scores_train, train_neg, train_pos, fused_train_file, scores_dev_lines=None, scores_dev=None, dev_neg=None, dev_pos=None, fused_dev_file=None, scores_eval_lines=None, scores_eval=None, fused_eval_file=None, force=False, min_file_size=1000, do_training=True)[source]