Commit 598a1671 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'vanilla_pad_decision_function' into 'master'

Allow to specify the pipeline decision function in vanilla_pad script

See merge request !85
parents 9ae20678 70d48771
Pipeline #49364 passed with stages
in 9 minutes and 9 seconds
......@@ -28,13 +28,21 @@ from bob.pipelines.distributed import dask_get_partition_size
help="Feature extraction algorithm",
cls=ResourceOption,
)
@click.option(
"--decision_function",
"-f",
show_default=True,
default="decision_function",
help="Name of the Pipeline step to call for results, eg 'score' or 'predict'",
cls=ResourceOption,
)
@click.option(
"--database",
"-d",
required=True,
cls=ResourceOption,
entry_point_group="bob.pad.database",
help="PAD Database connector (class that implements the methods: `fit_samples`, `predict_samples`)",
cls=ResourceOption,
)
@click.option(
"--dask-client",
......@@ -49,10 +57,11 @@ from bob.pipelines.distributed import dask_get_partition_size
"--group",
"-g",
"groups",
type=click.Choice(["dev", "eval"]),
type=click.Choice(["train", "dev", "eval"]),
multiple=True,
default=("dev", "eval"),
help="If given, this value will limit the experiments belonging to a particular group",
cls=ResourceOption,
)
@click.option(
"-o",
......@@ -60,6 +69,7 @@ from bob.pipelines.distributed import dask_get_partition_size
show_default=True,
default="results",
help="Saves scores (and checkpoints) in this folder.",
cls=ResourceOption,
)
@click.option(
"--checkpoint",
......@@ -93,6 +103,7 @@ from bob.pipelines.distributed import dask_get_partition_size
def vanilla_pad(
ctx,
pipeline,
decision_function,
database,
dask_client,
groups,
......@@ -169,7 +180,7 @@ def vanilla_pad(
for group in groups:
logger.info(f"Running vanilla biometrics for group {group}")
result = pipeline.decision_function(predict_samples[group])
result = getattr(pipeline, decision_function)(predict_samples[group])
scores_path = os.path.join(output, f"scores-{group}")
......
......@@ -108,6 +108,9 @@ Here is the minimal structure of a classifier:
def predict(self, X):
return do_prediction(self.state, X)
def decision_function(self, X):
return do_decision(X)
.. note::
The easiest method is to use a scikit-learn classifier, like :py:class:`sklearn.svm.SVC`.
......@@ -145,9 +148,14 @@ The pipeline can then be executed with the command::
$ bob pad vanilla-pad -d my_database_config.py -p my_pipeline_config.py -o output_dir
When executed with vanilla-pad, every training sample will pass through the pipeline, executing the ``fit`` methods.
Then, every sample of the `dev` set (and/or the `eval` set) will be given to the `transform` method of ``my_transformer`` and the result is passed to the `predict` method of ``my_classifier``.
Then, every sample of the `dev` set (and/or the `eval` set) will be given to the `transform` method of ``my_transformer`` and the result is passed to the ``decision_function`` method of ``my_classifier``.
The output of the classifier (scores) is written to a file.
.. note::
By default, vanilla-pad expects the classifier to have a `decision_function` method to call for the prediction step. It can be changed with the '-f' switch to the prediction method of your classifier, for instance `-f predict_proba` to use this method of your scikit-learn classifiers.
The usual `decision_function` of scikit-learn is their `predict_proba` method.
.. _bob.pad.base.using_sklearn_classifiers:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment