Commit 54b3600e authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Optimize scoring if allow_scoring_with_all_biometric_references == False

parent d9c1669b
Pipeline #45945 failed with stage
in 9 minutes and 36 seconds
......@@ -31,7 +31,7 @@ class BioAlgorithm(metaclass=ABCMeta):
def __init__(self, score_reduction_operation=average_scores,**kwargs):
def __init__(self, score_reduction_operation=average_scores, **kwargs):
self.stacked_biometric_references = None
self.score_reduction_operation = average_scores
......@@ -163,19 +163,45 @@ class BioAlgorithm(metaclass=ABCMeta):
# There are some protocols where each probe has
# to be scored with a specific list of biometric_references
total_scores = []
if self.stacked_biometric_references is None:
self.stacked_biometric_references = dict()
def cache_references(probe_refererences):
Stack referecences in a dictionary
for r in biometric_references:
if (
str(r.subject) in probe_refererences
and str(r.subject) not in self.stacked_biometric_references
self.stacked_biometric_references[str(r.subject)] =
for probe_sample in sampleset:
scores = []
for ref in [
r for r in biometric_references if str(r.subject) in sampleset.references
references = [
for r in biometric_references
if str(r.subject) in sampleset.references
scores = self.score_multiple_biometric_references(
total_scores = self.score_reduction_operation(np.array(total_scores))
for ref, score in zip([
r for r in biometric_references if str(r.subject) in sampleset.references
], total_scores):
for ref, score in zip(
for r in biometric_references
if str(r.subject) in sampleset.references
scores_biometric_references.append(Sample(score, parent=ref))
......@@ -187,7 +213,6 @@ class BioAlgorithm(metaclass=ABCMeta):
return SampleSet(scores_biometric_references, parent=sampleset, **kwargs)
def score(self, biometric_reference, data):
"""It handles the score computation for one sample
......@@ -226,7 +251,9 @@ class BioAlgorithm(metaclass=ABCMeta):
Data used for the creation of ONE BIOMETRIC REFERENCE
raise NotImplementedError("Your BioAlgorithm implementation should implement score_multiple_biometric_references.")
raise NotImplementedError(
"Your BioAlgorithm implementation should implement score_multiple_biometric_references."
class Database(metaclass=ABCMeta):
......@@ -310,6 +337,7 @@ class ScoreWriter(metaclass=ABCMeta):
import dask.bag
import dask
if isinstance(score_paths, dask.bag.Bag):
all_paths = dask.delayed(list)(score_paths)
return dask.delayed(_post_process)(all_paths, filename)
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