diff --git a/bob/bio/base/pipelines/vanilla_biometrics/abstract_classes.py b/bob/bio/base/pipelines/vanilla_biometrics/abstract_classes.py index f598e7cd030a8fd5158aa07a715de775bdd289b7..97fa6e70fe928af2709c369c68af2b5a565f37ad 100644 --- a/bob/bio/base/pipelines/vanilla_biometrics/abstract_classes.py +++ b/bob/bio/base/pipelines/vanilla_biometrics/abstract_classes.py @@ -96,7 +96,6 @@ class BioAlgorithm(metaclass=ABCMeta): # a sampleset either after or before scoring. # To be honest, this should be the default behaviour retval = [] - for subprobe_id, (s, parent) in enumerate(zip(data, sampleset.samples)): # Creating one sample per comparison subprobe_scores = [] @@ -104,7 +103,9 @@ class BioAlgorithm(metaclass=ABCMeta): r for r in biometric_references if r.key in sampleset.references ]: score = self.score(ref.data, s) - data = make_score_line(ref.subject, sampleset.subject, sampleset.path, score) + data = make_four_colums_score( + ref.subject, sampleset.subject, sampleset.path, score + ) subprobe_scores.append(Sample(data, parent=ref)) # Creating one sampleset per probe @@ -195,32 +196,23 @@ class Database(metaclass=ABCMeta): pass -def make_score_line( +def make_four_colums_score( biometric_reference_subject, probe_subject, probe_path, score, ): data = "{0} {1} {2} {3}\n".format( - biometric_reference_subject, - probe_subject, - probe_path, - score, + biometric_reference_subject, probe_subject, probe_path, score, ) return data -def save_scores_four_columns(path, probe): +def create_score_delayed_sample(path, probe): """ Write scores in the four columns format """ with open(path, "w") as f: - for biometric_reference in probe.samples: - line = make_score_line( - biometric_reference.subject, - probe.subject, - probe.path, - biometric_reference.data, - ) - f.write(line) + for score_line in probe.samples: + f.write(score_line.data) def load(): with open(path) as f: diff --git a/bob/bio/base/pipelines/vanilla_biometrics/mixins.py b/bob/bio/base/pipelines/vanilla_biometrics/mixins.py index c335a9aae5a4e9f142fd155f44541304aac7da29..af26b8363cb40d78a8c22e47fac97712d0d94339 100644 --- a/bob/bio/base/pipelines/vanilla_biometrics/mixins.py +++ b/bob/bio/base/pipelines/vanilla_biometrics/mixins.py @@ -4,7 +4,7 @@ import bob.io.base import os import functools import dask -from .abstract_classes import save_scores_four_columns +from .abstract_classes import create_score_delayed_sample class BioAlgCheckpointMixin(CheckpointMixin): @@ -61,9 +61,7 @@ class BioAlgCheckpointMixin(CheckpointMixin): else: # If sample already there, just load - delayed_enrolled_sample = self.load(path) - delayed_enrolled_sample.key = sampleset.key - delayed_enrolled_sample.subject = sampleset.subject + delayed_enrolled_sample = self.load(sampleset, path) return delayed_enrolled_sample @@ -76,9 +74,9 @@ class BioAlgCheckpointMixin(CheckpointMixin): for s in scored_sample_set: # Checkpointing score path = os.path.join(self.score_dir, str(s.path) + ".txt") - bob.io.base.create_directories_safe(os.path.dirname(path)) + os.makedirs(os.path.dirname(path), exist_ok=True) - delayed_scored_sample = save_scores_four_columns(path, s) + delayed_scored_sample = create_score_delayed_sample(path, s) s.samples = [delayed_scored_sample] return scored_sample_set