Commit 37c03d67 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Merge branch 'chain' into 'master'

Write parameters in a temporary config file to enable chain loading

Closes #116

See merge request !155
parents fa750002 449a70c5
Pipeline #20550 passed with stage
in 13 minutes and 55 seconds
......@@ -34,7 +34,7 @@ def get_available_databases():
available_databases[database]["groups"] = []
# Searching for database groups
groups = list(database_entry_point.groups())
groups = list(database_entry_point.groups()) or ["dev"]
for g in ["dev", "eval"]:
available_databases[database]["groups"] += [g] if g in groups else []
except Exception:
......@@ -8,11 +8,15 @@ A script to run biometric recognition baselines
from .. import load_resource
import os
from .verify import main as verify
from ..baseline import get_available_databases, search_preprocessor
from bob.extension.scripts.click_helper import verbosity_option
import click
import tempfile
import logging
import os
logger = logging.getLogger("")
@click.command(context_settings={'ignore_unknown_options': True,
......@@ -45,29 +49,52 @@ def baseline(ctx, baseline, database):
Hint: pass `--temp-directory <dir>` to set the directory for temporary files
Hint: pass `--result-directory <dir>` to set the directory for resulting score files
# Triggering training for each baseline/database
loaded_baseline = load_resource(
baseline, 'baseline', package_prefix="")
# this is the default sub-directory that is used
sub_directory = os.path.join(database, baseline)
# find the compatible preprocessor for this database
database_data = get_available_databases()[database]
db = search_preprocessor(database, loaded_baseline.preprocessors.keys())
preprocessor = loaded_baseline.preprocessors[db]
# call verify with all parameters
parameters = [
'-p', preprocessor,
'-e', loaded_baseline.extractor,
'-d', database,
'-a', loaded_baseline.algorithm,
'--sub-directory', sub_directory
] + ['-v'] * ctx.meta['verbosity']
parameters += ['--groups'] + database_data["groups"]
# this is the default sub-directory that is used
if "-T" in ctx.args or "--temp-directory" in ctx.args:
sub_directory = os.path.join(database, baseline)
sub_directory = baseline
logger.debug('Database groups are %s', database_data["groups"])
# call verify with newly generated config file. We will create a new config
# file to allow people to use chain-loading and further modify the
# baselines. See:
config = '''
preprocessor = '{preprocessor}'
extractor = '{extractor}'
algorithm = '{algorithm}'
database = '{database}'
sub_directory = '{sub_directory}'
groups = ['{groups}']
verbose = {verbose}
groups="', '".join(database_data["groups"]),
with tempfile.NamedTemporaryFile(mode='w+t', prefix='{}_'.format(baseline),
suffix='.py', delete=False, dir='.') as f:
verify([] + ctx.args)
click.echo("You may want to delete `{}' after the experiments are "
"finished running.".format(
verify(parameters + ctx.args)
......@@ -10,11 +10,11 @@ def test_baselines():
runner = CliRunner()
result = runner.invoke(baseline, args=('dummy', 'dummy', '-T', tmp_dir, '-R', tmp_dir))
assertion_error_message = (
'Command exited with this output: `{}\' \n'
'Command exited with this output and exception: `{}\' \n `{}\' \n'
'If the output is empty, you can run this script locally to see '
'what is wrong:\n'
'bin/bob bio baseline -d dummy -a dummy -o /tmp/temp_annotations'
'bin/bob bio baseline dummy dummy -T /tmp/baseline -R /tmp/baseline'
''.format(result.output, result.exception))
assert result.exit_code == 0, assertion_error_message
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