diff --git a/bob/bio/base/algorithm/Algorithm.py b/bob/bio/base/algorithm/Algorithm.py index ab73d596a13909df3e1f5751adb0dc78048c11a6..6023d3df0cf00e6a16e38cbd79930120094ac6b5 100644 --- a/bob/bio/base/algorithm/Algorithm.py +++ b/bob/bio/base/algorithm/Algorithm.py @@ -98,7 +98,7 @@ class Algorithm: info : str A string containing the full information of all parameters of this (and the derived) class. """ - return "%s(%s)" % (str(self.__class__), ", ".join(["%s=%s" % (key, value) for key,value in self._kwargs.items() if value is not None])) + return utils.pretty_print(self, self._kwargs) def project(self, feature): diff --git a/bob/bio/base/extractor/Extractor.py b/bob/bio/base/extractor/Extractor.py index 83ee6c6d6097afec3d366d8155b93af3b5302af9..6dd59a5536d7ecd604235bb7202f4bcd096cf4ff 100644 --- a/bob/bio/base/extractor/Extractor.py +++ b/bob/bio/base/extractor/Extractor.py @@ -88,7 +88,7 @@ class Extractor: info : str A string containing the full information of all parameters of this (and the derived) class. """ - return "%s(%s)" % (str(self.__class__), ", ".join(["%s=%s" % (key, value) for key,value in self._kwargs.items() if value is not None])) + return utils.pretty_print(self, self._kwargs) ############################################################ diff --git a/bob/bio/base/grid.py b/bob/bio/base/grid.py index 447575debbbe7246926f7219e4112285cf26040e..9dcef208f099ec0f613b6a11fee7fcc82073cd82 100644 --- a/bob/bio/base/grid.py +++ b/bob/bio/base/grid.py @@ -91,6 +91,15 @@ class Grid: ): self.grid_type = grid_type + if self.is_local(): + self._kwargs = dict(grid_type=grid_type, number_of_parallel_processes=number_of_parallel_processes, scheduler_sleep_time=scheduler_sleep_time) + else: + self._kwargs = dict( + grid_type=grid_type, + number_of_preprocessing_jobs=number_of_preprocessing_jobs, number_of_extraction_jobs=number_of_extraction_jobs, number_of_projection_jobs=number_of_projection_jobs, number_of_enrollment_jobs=number_of_enrollment_jobs, + training_queue=training_queue, preprocessing_queue=preprocessing_queue, extraction_queue=extraction_queue, projection_queue=projection_queue, enrollment_queue=enrollment_queue, scoring_queue=scoring_queue + ) + # the numbers if self.is_local(): @@ -118,6 +127,10 @@ class Grid: self.scheduler_sleep_time = scheduler_sleep_time + def __str__(self): + """Converts this grid configuration into a string, which contains the complete set of parameters.""" + return utils.pretty_print(self, self._kwargs) + def queue(self, params): """queue(params) -> dict diff --git a/bob/bio/base/preprocessor/Preprocessor.py b/bob/bio/base/preprocessor/Preprocessor.py index 5f054e11dfa5a9545e1f3045aa2e85007675fa40..4203b518afd145fc47dacbff4ae8b57135deca69 100644 --- a/bob/bio/base/preprocessor/Preprocessor.py +++ b/bob/bio/base/preprocessor/Preprocessor.py @@ -78,7 +78,7 @@ class Preprocessor: info : str A string containing the full information of all parameters of this (and the derived) class. """ - return "%s(%s)" % (str(self.__class__), ", ".join(["%s=%s" % (key, value) for key,value in self._kwargs.items() if value is not None])) + return utils.pretty_print(self, self._kwargs) ############################################################ ### Special functions that might be overwritten on need diff --git a/bob/bio/base/script/resources.py b/bob/bio/base/script/resources.py index 3ede22ed6eeae2676f453573c09db45a52db1964..96ad15689bd5fd40da6f0996f573f8e00cc98b24 100644 --- a/bob/bio/base/script/resources.py +++ b/bob/bio/base/script/resources.py @@ -8,20 +8,23 @@ def resources(): import argparse parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument("--details", '-d', nargs = '+', + parser.add_argument("--types", '-t', nargs = '+', choices = ('d', 'database', 'p', 'preprocessor', 'e', 'extractor', 'a', 'algorithm', 'g', 'grid'), default = ('d', 'p', 'e', 'a', 'g'), help = "Select the resource types that should be listed.") + parser.add_argument("--details", '-d', action='store_true', help = "Prints the complete configuration for all resources") + parser.add_argument("--no-strip-dummy", '-s', action = 'store_true', help = "If given, the dummy elements (usually used for testing purposes only) are **not** removed from the list.") args = parser.parse_args() - kwargs = {} + kwargs = {'verbose' : args.verbose} if args.no_strip_dummy: kwargs['strip'] = [] + if 'd' in args.details or 'database' in args.details: print ("\nList of registered databases:") print (bob.bio.base.list_resources('database', **kwargs)) diff --git a/bob/bio/base/utils/__init__.py b/bob/bio/base/utils/__init__.py index 330e58616a1764998cff2181f03cc31d6975ea12..6f8de4a4faef25d9a20e8f19d97fe363f1546b09 100644 --- a/bob/bio/base/utils/__init__.py +++ b/bob/bio/base/utils/__init__.py @@ -51,3 +51,7 @@ def selected_elements(list_of_elements, desired_number_of_elements = None): return list_of_elements # sub-select return [list_of_elements[i] for i in selected_indices(total_number_of_elements, desired_number_of_elements)] + +def pretty_print(obj, kwargs): + """Returns a pretty-print of the parameters to the constructor of a class, which should be able to copy-paste on the command line to create the object (with few exceptions).""" + return "%s(%s)" % (str(obj.__class__), ", ".join(["%s='%s'" % (key,value) if isinstance(value, str) else "%s=%s" % (key, value) for key,value in kwargs.items() if value is not None])) diff --git a/bob/bio/base/utils/resources.py b/bob/bio/base/utils/resources.py index bf6791f27b06bdc1273b3f81dd162a06d7624cce..fedb73e2936cceece16ecd275f365c3d7100b6f4 100644 --- a/bob/bio/base/utils/resources.py +++ b/bob/bio/base/utils/resources.py @@ -178,7 +178,7 @@ def extensions(keywords=valid_keywords, package_prefix='bob.bio.'): keywords : [str] A list of keywords to load entry points for. Defaults to all :py:attr:`valid_keywords`. - + package_prefix : str Package namespace, in which we search for entry points, e.g., ``bob.bio``. """ @@ -194,7 +194,7 @@ def resource_keys(keyword, exclude_packages=[], package_prefix='bob.bio.', strip if entry_point.dist.project_name not in exclude_packages]) -def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.'): +def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=False): """Returns a string containing a detailed list of resources that are registered with the given keyword.""" if keyword not in valid_keywords: raise ValueError("The given keyword '%s' is not valid. Please use one of %s!" % (str(keyword), str(valid_keywords))) @@ -213,6 +213,9 @@ def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.'): retval += " + %s --> %s: %s\n" % (entry_point.name + " "*(length - len(entry_point.name)), entry_point.module_name, entry_point.attrs[0]) else: retval += " + %s --> %s\n" % (entry_point.name + " "*(length - len(entry_point.name)), entry_point.module_name) + if verbose: + retval += " ==> " + str(entry_point.load()) + "\n\n" + return retval diff --git a/doc/experiments.rst b/doc/experiments.rst index b01e259709478efa25d2c6fb0198996c3183c81e..536037ab5795ee86f6fc3248a78fef5a3b5d088c 100644 --- a/doc/experiments.rst +++ b/doc/experiments.rst @@ -82,7 +82,13 @@ To get a list of registered resources, please call: $ ./bin/resources.py Each package in ``bob.bio`` defines its own resources, and the printed list of registered resources differs according to the installed packages. -If only ``bob.bio.base`` is installed, no databases and no preprocessors will be listed. +If only ``bob.bio.base`` is installed, no databases and only one preprocessor will be listed. +To see more details about the resources, i.e., the full constructor call fo the respective class, use the ``--details`` (or shortly ``-d``) option, and to sub-select only specific types of resources, use the ``--types`` (or ``-t``) option: + +.. code-block:: sh + + $ ./bin/resources.py -dt algorithm + .. note:: You will also find some ``grid`` resources being listed.