diff --git a/bob/bio/base/baseline/Baseline.py b/bob/bio/base/baseline/Baseline.py index 40459ccad63c444709e6092b37d20b29e9048d33..36912797ff819507b0775ed82a0a50fd39dec72a 100644 --- a/bob/bio/base/baseline/Baseline.py +++ b/bob/bio/base/baseline/Baseline.py @@ -34,7 +34,7 @@ def get_available_databases(): available_databases[database]["groups"] = [] # Searching for database groups try: - 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: diff --git a/bob/bio/base/script/baseline.py b/bob/bio/base/script/baseline.py index 74c219446b86748e2f5b0ce343f46c1332236e3b..63758fae181dea04221cf19dab78c614f1731677 100644 --- a/bob/bio/base/script/baseline.py +++ b/bob/bio/base/script/baseline.py @@ -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("bob.bio.base") @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="bob.bio.") - # 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) + else: + 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: https://gitlab.idiap.ch/bob/bob.bio.video/issues/12 + config = ''' +preprocessor = '{preprocessor}' +extractor = '{extractor}' +algorithm = '{algorithm}' +database = '{database}' +sub_directory = '{sub_directory}' +groups = ['{groups}'] +verbose = {verbose} +'''.format( + preprocessor=preprocessor, + extractor=loaded_baseline.extractor, + algorithm=loaded_baseline.algorithm, + database=database, + sub_directory=sub_directory, + groups="', '".join(database_data["groups"]), + verbose=ctx.meta['verbosity'], + ) + + with tempfile.NamedTemporaryFile(mode='w+t', prefix='{}_'.format(baseline), + suffix='.py', delete=False, dir='.') as f: + f.write(config) + f.flush() + f.seek(0) + verify([f.name] + ctx.args) + click.echo("You may want to delete `{}' after the experiments are " + "finished running.".format(f.name)) - verify(parameters + ctx.args) diff --git a/bob/bio/base/test/test_baselines.py b/bob/bio/base/test/test_baselines.py index 27dd5749b5eab5a7cbef8853753e25e41c218731..595505b83bc5c3819ec406ee63b9d68e341b7d25 100644 --- a/bob/bio/base/test/test_baselines.py +++ b/bob/bio/base/test/test_baselines.py @@ -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' - ''.format(result.output)) + '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 finally: