Commit 49a62900 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Using config file loading mechanism from bob.extension

Removed global variable results

Using config file loading mechanism from bob.extension

Used the bob.extension config file loading

Removing an awesome feature implemented in 2 lines of code

Integrated with bob.extension merge 58

[sphinx] Added some documentation about chain loading

Fixed import
parent 21e7371f
Pipeline #14571 passed with stages
in 23 minutes and 54 seconds
......@@ -184,28 +184,32 @@ def add_results(args, nonorm, ztnorm = None):
else:
r.ztnorm(dev_file)
global results
results.append(r)
return r
def recurse(args, path):
"""Recurse the directory structure and collect all results that are stored in the desired file names."""
dir_list = os.listdir(path)
results = []
# check if the score directories are included in the current path
if args.nonorm in dir_list or args.nonorm == '.':
if args.ztnorm in dir_list or args.ztnorm == '.':
add_results(args, os.path.join(path, args.nonorm), os.path.join(path, args.ztnorm))
return results + [add_results(args, os.path.join(path, args.nonorm), os.path.join(path, args.ztnorm))]
else:
add_results(args, os.path.join(path, args.nonorm))
return results + [add_results(args, os.path.join(path, args.nonorm))]
for e in dir_list:
real_path = os.path.join(path, e)
if os.path.isdir(real_path):
recurse(args, real_path)
r = recurse(args, real_path)
if r is not None:
results += r
return results
def table():
def table(results):
"""Generates a table containing all results in a nice format."""
A = " "*2 + 'dev nonorm'+ " "*5 + 'dev ztnorm' + " "*6 + 'eval nonorm' + " "*4 + 'eval ztnorm' + " "*12 + 'directory\n'
A += "-"*100+"\n"
......@@ -219,12 +223,13 @@ def main(command_line_parameters = None):
"""Iterates through the desired directory and collects all result files."""
args = command_line_arguments(command_line_parameters)
global results
results = []
# collect results
directories = glob.glob(args.directory)
for directory in directories:
recurse(args, directory)
r = recurse(args, directory)
if r is not None:
results += r
# sort results if desired
if args.sort:
......@@ -233,10 +238,10 @@ def main(command_line_parameters = None):
# print the results
if args.self_test:
table()
table(results)
elif args.output:
f = open(args.output, "w")
f.writelines(table())
f.writelines(table(results))
f.close()
else:
print (table())
print (table(results))
......@@ -241,7 +241,6 @@ def take_from_config_or_command_line(args, config, keyword, default, required=Tr
preferred_package=args.preferred_package))
elif config is not None and hasattr(config, keyword):
val = getattr(config, keyword)
if isinstance(val, str) and is_resource:
val = utils.load_resource(val, keyword, imports=args.imports, package_prefix=args.package_prefix,
......@@ -295,7 +294,7 @@ def parse_config_file(parsers, args, args_dictionary, keywords, skips):
take_from_config_or_command_line(args, config, "sub_directory",
parser.get_default("sub_directory"), is_resource=False)
skip_keywords = tuple(['skip_' + k.replace('-', '_') for k in skips])
for keyword in keywords + skip_keywords + ('execute_only',):
......
......@@ -8,7 +8,7 @@ from __future__ import print_function
import imp
import os
import pkg_resources
import bob.extension.config
import sys
if sys.version_info[0] == 2:
from string import letters as ascii_letters
......@@ -45,45 +45,7 @@ def _collect_config(paths):
'''
def _attach_resources(src, dst):
for k in dir(src):
setattr(dst, k, getattr(src, k))
import random
name = "".join(random.sample(ascii_letters, 10))
retval = imp.new_module(name)
for path in paths:
# execute the module code on the context of previously import modules
for ep in pkg_resources.iter_entry_points('bob.bio.config'):
if ep.name == path:
tmp = ep.load() # loads the pointed module
_attach_resources(tmp, retval)
break
else:
# if you get to this point, then it is not a resource, maybe it is a module?
try:
tmp = __import__(path, retval.__dict__, retval.__dict__, ['*'])
_attach_resources(tmp, retval)
continue
except ImportError:
# module does not exist, ignore it
pass
except Exception as e:
raise IOError("The configuration module '%s' could not be loaded: %s" % (path, e))
# if you get to this point, then its not a resource nor a loadable module, is
# it on the file system?
if not os.path.exists(path):
raise IOError("The configuration file, resource or module '%s' could not be found, loaded or imported" % path)
name = "".join(random.sample(ascii_letters, 10))
tmp = imp.load_source(name, path)
_attach_resources(tmp, retval)
return retval
return bob.extension.config.load(paths, entry_point_group="bob.bio.config")
def read_config_file(filenames, keyword = None):
......
......@@ -94,6 +94,18 @@ Running the experiment is then as simple as:
.. note::
To be able to run exactly the command line from above, it requires to have :ref:`bob.bio.face <bob.bio.face>` installed.
.. note::
Chain loading is possible through configuration files, i.e., variables of each
config is available during evaluation of the preceding config file.
This allows us to spread our experiment setup in several configuration files and have a call similar to this::
$ verify.py config_1.py config_2.py config_n.py
For more information see *Chain Loading* in :ref:`bob.extension.config`.
Before running an experiment, it is recommended to add set the variable ``dry_run = True``, so that it will only print, which steps would be executed, without actually executing them, and make sure that everything works as expected.
The final result of the experiment will be one (or more) score file(s).
......@@ -102,7 +114,7 @@ By default, you can find them in a sub-directory the ``result`` directory, but y
.. note::
At Idiap_, the default result directory differs, see ``verify.py --help`` for your directory.
.. _bob.bio.base.command_line:
......
Supports Markdown
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