Added the memory_demanding attribute as part of the legacy APi

parent 97cc2b19
Pipeline #46077 passed with stage
in 13 minutes and 4 seconds
......@@ -22,9 +22,7 @@ logger = logging.getLogger("bob.bio.base")
def _biofile_to_delayed_sample(biofile, database):
return DelayedSample(
load=functools.partial(
biofile.load,
database.original_directory,
database.original_extension,
biofile.load, database.original_directory, database.original_extension,
),
subject=str(biofile.client_id),
key=biofile.path,
......@@ -65,6 +63,10 @@ class DatabaseConnector(Database):
fixed_positions: dict
In case database contains one single annotation for all samples.
This is useful for registered databases.
memory_demanding: bool
Sinalizes that a database has some memory demanding components.
It might be useful for future processing
"""
def __init__(
......@@ -73,6 +75,7 @@ class DatabaseConnector(Database):
allow_scoring_with_all_biometric_references=True,
annotation_type="eyes-center",
fixed_positions=None,
memory_demanding=False,
**kwargs,
):
self.database = database
......@@ -81,6 +84,7 @@ class DatabaseConnector(Database):
)
self.annotation_type = annotation_type
self.fixed_positions = fixed_positions
self.memory_demanding = memory_demanding
def background_model_samples(self):
"""Returns :py:class:`Sample`'s to train a background model (group
......@@ -204,12 +208,7 @@ class BioAlgorithmLegacy(BioAlgorithm):
"""
def __init__(
self,
instance,
base_dir,
force=False,
projector_file=None,
**kwargs,
self, instance, base_dir, force=False, projector_file=None, **kwargs,
):
super().__init__(**kwargs)
......
......@@ -9,8 +9,9 @@ import six
import inspect
import numpy
def score_fusion_strategy(strategy_name = 'average'):
"""Returns a function to compute a fusion strategy between different scores.
def score_fusion_strategy(strategy_name="average"):
"""Returns a function to compute a fusion strategy between different scores.
Different strategies are employed:
......@@ -20,46 +21,68 @@ def score_fusion_strategy(strategy_name = 'average'):
* ``'median'`` : The median score is computed using the :py:func:`numpy.median` function.
* ``None`` is also accepted, in which case ``None`` is returned.
"""
try:
return {
'average' : numpy.average,
'min' : min,
'max' : max,
'median' : numpy.median,
None : None
}[strategy_name]
except KeyError:
# warn("score fusion strategy '%s' is unknown" % strategy_name)
return None
def selected_indices(total_number_of_indices, desired_number_of_indices = None):
"""Returns a list of indices that will contain exactly the number of desired indices (or the number of total items in the list, if this is smaller).
try:
return {
"average": numpy.average,
"min": min,
"max": max,
"median": numpy.median,
None: None,
}[strategy_name]
except KeyError:
# warn("score fusion strategy '%s' is unknown" % strategy_name)
return None
def selected_indices(total_number_of_indices, desired_number_of_indices=None):
"""Returns a list of indices that will contain exactly the number of desired indices (or the number of total items in the list, if this is smaller).
These indices are selected such that they are evenly spread over the whole sequence."""
if desired_number_of_indices is None or desired_number_of_indices >= total_number_of_indices or desired_number_of_indices < 0:
return range(total_number_of_indices)
increase = float(total_number_of_indices)/float(desired_number_of_indices)
# generate a regular quasi-random index list
return [int((i +.5)*increase) for i in range(desired_number_of_indices)]
def selected_elements(list_of_elements, desired_number_of_elements = None):
"""Returns a list of elements that are sub-selected from the given list (or the list itself, if its length is smaller).
if (
desired_number_of_indices is None
or desired_number_of_indices >= total_number_of_indices
or desired_number_of_indices < 0
):
return range(total_number_of_indices)
increase = float(total_number_of_indices) / float(desired_number_of_indices)
# generate a regular quasi-random index list
return [int((i + 0.5) * increase) for i in range(desired_number_of_indices)]
def selected_elements(list_of_elements, desired_number_of_elements=None):
"""Returns a list of elements that are sub-selected from the given list (or the list itself, if its length is smaller).
These elements are selected such that they are evenly spread over the whole list."""
total_number_of_elements = len(list_of_elements)
if desired_number_of_elements is None or desired_number_of_elements >= total_number_of_elements or desired_number_of_elements < 0:
return list_of_elements
# sub-select
return [list_of_elements[i] for i in selected_indices(total_number_of_elements, desired_number_of_elements)]
total_number_of_elements = len(list_of_elements)
if (
desired_number_of_elements is None
or desired_number_of_elements >= total_number_of_elements
or desired_number_of_elements < 0
):
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, six.string_types) else "%s=%s" % (key, value) for key,value in kwargs.items() if value is not None]))
"""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, six.string_types)
else "%s=%s" % (key, value)
for key, value in kwargs.items()
if value is not None
]
),
)
def is_argument_available(argument, method):
"""
"""
Check if an argument (or keyword argument) is available in a method
Attributes
......@@ -72,7 +95,7 @@ def is_argument_available(argument, method):
"""
if six.PY2:
return argument in inspect.getargspec(method).args
else:
return argument in inspect.signature(method).parameters.keys()
if six.PY2:
return argument in inspect.getargspec(method).args
else:
return argument in inspect.signature(method).parameters.keys()
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