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 ...@@ -28,13 +28,21 @@ from bob.pipelines.distributed import dask_get_partition_size
help="Feature extraction algorithm", help="Feature extraction algorithm",
cls=ResourceOption, 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( @click.option(
"--database", "--database",
"-d", "-d",
required=True, required=True,
cls=ResourceOption,
entry_point_group="bob.pad.database", entry_point_group="bob.pad.database",
help="PAD Database connector (class that implements the methods: `fit_samples`, `predict_samples`)", help="PAD Database connector (class that implements the methods: `fit_samples`, `predict_samples`)",
cls=ResourceOption,
) )
@click.option( @click.option(
"--dask-client", "--dask-client",
...@@ -49,10 +57,11 @@ from bob.pipelines.distributed import dask_get_partition_size ...@@ -49,10 +57,11 @@ from bob.pipelines.distributed import dask_get_partition_size
"--group", "--group",
"-g", "-g",
"groups", "groups",
type=click.Choice(["dev", "eval"]), type=click.Choice(["train", "dev", "eval"]),
multiple=True, multiple=True,
default=("dev", "eval"), default=("dev", "eval"),
help="If given, this value will limit the experiments belonging to a particular group", help="If given, this value will limit the experiments belonging to a particular group",
cls=ResourceOption,
) )
@click.option( @click.option(
"-o", "-o",
...@@ -60,6 +69,7 @@ from bob.pipelines.distributed import dask_get_partition_size ...@@ -60,6 +69,7 @@ from bob.pipelines.distributed import dask_get_partition_size
show_default=True, show_default=True,
default="results", default="results",
help="Saves scores (and checkpoints) in this folder.", help="Saves scores (and checkpoints) in this folder.",
cls=ResourceOption,
) )
@click.option( @click.option(
"--checkpoint", "--checkpoint",
...@@ -93,6 +103,7 @@ from bob.pipelines.distributed import dask_get_partition_size ...@@ -93,6 +103,7 @@ from bob.pipelines.distributed import dask_get_partition_size
def vanilla_pad( def vanilla_pad(
ctx, ctx,
pipeline, pipeline,
decision_function,
database, database,
dask_client, dask_client,
groups, groups,
...@@ -169,7 +180,7 @@ def vanilla_pad( ...@@ -169,7 +180,7 @@ def vanilla_pad(
for group in groups: for group in groups:
logger.info(f"Running vanilla biometrics for group {group}") 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}") scores_path = os.path.join(output, f"scores-{group}")
......
...@@ -107,6 +107,9 @@ Here is the minimal structure of a classifier: ...@@ -107,6 +107,9 @@ Here is the minimal structure of a classifier:
def predict(self, X): def predict(self, X):
return do_prediction(self.state, X) return do_prediction(self.state, X)
def decision_function(self, X):
return do_decision(X)
.. note:: .. note::
...@@ -145,9 +148,14 @@ The pipeline can then be executed with the command:: ...@@ -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 $ 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. 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. 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: .. _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