From 7cde58e5d90009d6902909b12a6c176d871bb20e Mon Sep 17 00:00:00 2001
From: Olegs NIKISINS <onikisins@italix03.idiap.ch>
Date: Mon, 21 Jan 2019 12:13:10 +0100
Subject: [PATCH] Optimized reshape_flat_patches function in  patch_utils

---
 bob/pad/face/utils/patch_utils.py | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/bob/pad/face/utils/patch_utils.py b/bob/pad/face/utils/patch_utils.py
index cd14ec1e..13ac2aa2 100644
--- a/bob/pad/face/utils/patch_utils.py
+++ b/bob/pad/face/utils/patch_utils.py
@@ -45,16 +45,10 @@ def reshape_flat_patches(patches, patch_reshape_parameters = None):
 
         if patch_reshape_parameters is not None:
 
-            if len(patch_reshape_parameters)==2:
+            # The dimensionality of the reshaped patch:
+            new_shape = [np.int(len(patch)/(patch_reshape_parameters[-2]*patch_reshape_parameters[-1]))] + list(patch_reshape_parameters[-2:])
 
-                patch = patch.reshape(patch_reshape_parameters[0],
-                                      patch_reshape_parameters[1]) # reshape the patch
-
-            elif len(patch_reshape_parameters)==3:
-
-                patch = patch.reshape(patch_reshape_parameters[0],
-                                      patch_reshape_parameters[1],
-                                      patch_reshape_parameters[2]) # reshape the patch
+            patch = np.squeeze(patch.reshape(new_shape))
 
         patches_3d.append(patch)
 
-- 
GitLab