From 29e03aa4626c689d2c3bc0ae8f0d29b2b2fa350f Mon Sep 17 00:00:00 2001
From: Amir MOHAMMADI <amir.mohammadi@idiap.ch>
Date: Thu, 7 Jun 2018 14:48:04 +0200
Subject: [PATCH] Improve error handling in frame-diff

---
 bob/pad/face/extractor/FrameDiffFeatures.py  | 4 +++-
 bob/pad/face/preprocessor/FrameDifference.py | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/bob/pad/face/extractor/FrameDiffFeatures.py b/bob/pad/face/extractor/FrameDiffFeatures.py
index f7b2a941..7180b73a 100644
--- a/bob/pad/face/extractor/FrameDiffFeatures.py
+++ b/bob/pad/face/extractor/FrameDiffFeatures.py
@@ -246,7 +246,9 @@ class FrameDiffFeatures(Extractor):
 
         d_bg = self.cluster_5quantities(data[:, 1], window_size, overlap)
 
-        features = np.hstack((d_face, d_bg))
+        min_len = min(len(d_face), len(d_bg))
+
+        features = np.hstack((d_face[:min_len], d_bg[:min_len]))
 
         frames = self.convert_arr_to_frame_cont(features)
 
diff --git a/bob/pad/face/preprocessor/FrameDifference.py b/bob/pad/face/preprocessor/FrameDifference.py
index 62c4ae9b..8519c69d 100644
--- a/bob/pad/face/preprocessor/FrameDifference.py
+++ b/bob/pad/face/preprocessor/FrameDifference.py
@@ -225,6 +225,9 @@ class FrameDifference(Preprocessor):
             # annotations for particular frame
             frame_annotations = annotations[str(idx)]
 
+            if not frame_annotations:
+                continue
+
             # Estimate bottomright and topleft if they are not available:
             if 'topleft' not in frame_annotations:
                 bbx = bob.ip.facedetect.bounding_box_from_annotation(
-- 
GitLab