Skip to content
Snippets Groups Projects
Commit dec5fa81 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Write parameters in a temporary config file to enable chain loading

parent 46d00036
No related branches found
No related tags found
1 merge request!155Write parameters in a temporary config file to enable chain loading
Pipeline #
...@@ -34,7 +34,7 @@ def get_available_databases(): ...@@ -34,7 +34,7 @@ def get_available_databases():
available_databases[database]["groups"] = [] available_databases[database]["groups"] = []
# Searching for database groups # Searching for database groups
try: try:
groups = list(database_entry_point.groups()) groups = list(database_entry_point.groups()) or ["dev"]
for g in ["dev", "eval"]: for g in ["dev", "eval"]:
available_databases[database]["groups"] += [g] if g in groups else [] available_databases[database]["groups"] += [g] if g in groups else []
except Exception: except Exception:
......
...@@ -8,11 +8,14 @@ A script to run biometric recognition baselines ...@@ -8,11 +8,14 @@ A script to run biometric recognition baselines
from .. import load_resource from .. import load_resource
import os
from .verify import main as verify from .verify import main as verify
from ..baseline import get_available_databases, search_preprocessor from ..baseline import get_available_databases, search_preprocessor
from bob.extension.scripts.click_helper import verbosity_option from bob.extension.scripts.click_helper import verbosity_option
import click import click
import tempfile
import logging
logger = logging.getLogger("bob.bio.base")
@click.command(context_settings={'ignore_unknown_options': True, @click.command(context_settings={'ignore_unknown_options': True,
...@@ -45,29 +48,45 @@ def baseline(ctx, baseline, database): ...@@ -45,29 +48,45 @@ def baseline(ctx, baseline, database):
Hint: pass `--temp-directory <dir>` to set the directory for temporary files 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 Hint: pass `--result-directory <dir>` to set the directory for resulting score files
""" """
# Triggering training for each baseline/database # Triggering training for each baseline/database
loaded_baseline = load_resource( loaded_baseline = load_resource(
baseline, 'baseline', package_prefix="bob.bio.") 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 # find the compatible preprocessor for this database
database_data = get_available_databases()[database] database_data = get_available_databases()[database]
db = search_preprocessor(database, loaded_baseline.preprocessors.keys()) db = search_preprocessor(database, loaded_baseline.preprocessors.keys())
preprocessor = loaded_baseline.preprocessors[db] preprocessor = loaded_baseline.preprocessors[db]
# call verify with all parameters logger.debug('Database groups are %s', database_data["groups"])
parameters = [
'-p', preprocessor, # call verify with newly generated config file. We will create a new config
'-e', loaded_baseline.extractor, # file to allow people to use chain-loading and further modify the
'-d', database, # baselines. See: https://gitlab.idiap.ch/bob/bob.bio.video/issues/12
'-a', loaded_baseline.algorithm, config = '''
'--sub-directory', sub_directory preprocessor = '{preprocessor}'
] + ['-v'] * ctx.meta['verbosity'] extractor = '{extractor}'
algorithm = '{algorithm}'
parameters += ['--groups'] + database_data["groups"] database = '{database}'
sub_directory = '{sub_directory}'
verify(parameters + ctx.args) groups = ['{groups}']
verbose = {verbose}
'''.format(
preprocessor=preprocessor,
extractor=loaded_baseline.extractor,
algorithm=loaded_baseline.algorithm,
database=database,
sub_directory=baseline,
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))
...@@ -10,11 +10,11 @@ def test_baselines(): ...@@ -10,11 +10,11 @@ def test_baselines():
runner = CliRunner() runner = CliRunner()
result = runner.invoke(baseline, args=('dummy', 'dummy', '-T', tmp_dir, '-R', tmp_dir)) result = runner.invoke(baseline, args=('dummy', 'dummy', '-T', tmp_dir, '-R', tmp_dir))
assertion_error_message = ( 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 ' 'If the output is empty, you can run this script locally to see '
'what is wrong:\n' '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)) ''.format(result.output, result.exception))
assert result.exit_code == 0, assertion_error_message assert result.exit_code == 0, assertion_error_message
finally: finally:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment