From d320fbc65d5d760cb3f34de6550bab01d5bffcce Mon Sep 17 00:00:00 2001
From: Manuel Gunther <siebenkopf@googlemail.com>
Date: Wed, 11 May 2016 17:04:16 -0600
Subject: [PATCH] Allowing feature extraction and projection to fail, when
 --allow-missing-files is enabled

---
 bob/bio/base/tools/algorithm.py | 27 +++++++++++++++++++++++++++
 bob/bio/base/tools/extractor.py |  9 +++++++++
 2 files changed, 36 insertions(+)

diff --git a/bob/bio/base/tools/algorithm.py b/bob/bio/base/tools/algorithm.py
index e8e7c837..97740ca1 100644
--- a/bob/bio/base/tools/algorithm.py
+++ b/bob/bio/base/tools/algorithm.py
@@ -128,6 +128,15 @@ def project(algorithm, extractor, groups = None, indices = None, allow_missing_f
       feature = extractor.read_feature(feature_file)
       # project feature
       projected = algorithm.project(feature)
+
+      if projected is None:
+        if allow_missing_files:
+          logger.debug("... Projection for extracted file %s failed; skipping", feature_file)
+          continue
+        else:
+          logger.error("Projection of file '%s' was not successful", feature_file)
+        continue
+
       # write it
       algorithm.write_feature(projected, projected_file)
 
@@ -265,6 +274,15 @@ def enroll(algorithm, extractor, compute_zt_norm, indices = None, groups = ['dev
           enroll_features = [reader.read_feature(enroll_file) for enroll_file in enroll_files]
 
           model = algorithm.enroll(enroll_features)
+
+          if model is None:
+            if allow_missing_files:
+              logger.debug("... Enrollment for model %s failed; skipping", model_id)
+              continue
+            else:
+              logger.error("Enrollemnt of model '%s' was not successful", model_id)
+            continue
+
           # save the model
           algorithm.write_model(model, model_file)
 
@@ -303,6 +321,15 @@ def enroll(algorithm, extractor, compute_zt_norm, indices = None, groups = ['dev
           t_enroll_features = [reader.read_feature(t_enroll_file) for t_enroll_file in t_enroll_files]
 
           t_model = algorithm.enroll(t_enroll_features)
+
+          if t_model is None:
+            if allow_missing_files:
+              logger.debug("... Enrollment for T-model %s failed; skipping", t_model_id)
+              continue
+            else:
+              logger.error("Enrollemnt of T-model '%s' was not successful", t_model_id)
+            continue
+
           # save model
           algorithm.write_model(t_model, t_model_file)
         else:
diff --git a/bob/bio/base/tools/extractor.py b/bob/bio/base/tools/extractor.py
index 30a19cbe..5872a4ba 100644
--- a/bob/bio/base/tools/extractor.py
+++ b/bob/bio/base/tools/extractor.py
@@ -117,6 +117,15 @@ def extract(extractor, preprocessor, groups=None, indices = None, allow_missing_
       data = preprocessor.read_data(data_file)
       # extract feature
       feature = extractor(data)
+
+      if feature is None:
+        if allow_missing_files:
+          logger.debug("... Feature extraction for data file %s failed; skipping", data_file)
+          continue
+        else:
+          logger.error("Feature extraction  of file '%s' was not successful", data_file)
+        continue
+
       # write feature
       extractor.write_feature(feature, feature_file)
     else:
-- 
GitLab