From d6e7ca120bb8f1c5a8a928b101f88fe51bc3acd1 Mon Sep 17 00:00:00 2001
From: Pavel Korshunov <pavel.korshunov@idiap.ch>
Date: Thu, 28 Sep 2017 10:36:05 +0200
Subject: [PATCH] allow missing files scoring

---
 bob/pad/base/tools/scoring.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/bob/pad/base/tools/scoring.py b/bob/pad/base/tools/scoring.py
index 2aa81a7..aa5a53c 100644
--- a/bob/pad/base/tools/scoring.py
+++ b/bob/pad/base/tools/scoring.py
@@ -25,9 +25,8 @@ from bob.bio.base import utils
 def _compute_scores(algorithm, toscore_objects, allow_missing_files):
     """Compute scores for the given list of objects using provided algorithm.
     """
-    # the scores to be computed; initialized with NaN
-    scores = numpy.ones((1, len(toscore_objects)), numpy.float64) * numpy.nan
-    scores = numpy.reshape(scores, [len(toscore_objects)])
+    # the scores to be computed
+    scores = []
 
     # Loops over the toscore sets
     for i, toscore_element in enumerate(toscore_objects):
@@ -39,9 +38,9 @@ def _compute_scores(algorithm, toscore_objects, allow_missing_files):
         toscore = algorithm.read_toscore_object(toscore_element)
         # compute score
         if isinstance(toscore, list) or isinstance(toscore[0], numpy.ndarray):
-            scores[i] = algorithm.score_for_multiple_projections(toscore)
+            scores.insert(i, algorithm.score_for_multiple_projections(toscore))
         else:
-            scores[i] = algorithm.score(toscore)
+            scores.insert(i, algorithm.score(toscore))
     # Returns the scores
     return scores
 
@@ -107,6 +106,10 @@ def _save_scores(score_file, scores, toscore_objects, write_compressed=False):
         id_str = (str(toscore_object.client_id)).zfill(3)
         sample_name = str(toscore_object.make_path())
 
+        # we can have empty score list if allow_missing_files was true in _compute_scores()
+        if not scores[i]:
+            scores[i] = [numpy.nan]  # create a NaN score for such
+
         # scores[i] is a list, so
         # each sample is allowed to have multiple scores
         for score in scores[i]:
-- 
GitLab