From 7e74b2f096eb64e187ff20fab6488e0c1a64aca9 Mon Sep 17 00:00:00 2001
From: Tiago Freitas Pereira <tiagofrepereira@gmail.com>
Date: Fri, 24 Apr 2020 13:20:51 +0200
Subject: [PATCH] Removing traces of functools

---
 .../face/config/preprocessor/face_detect.py   |  5 +-
 bob/bio/face/preprocessor/utils.py            | 57 ++++++++++---------
 bob/bio/face/test/test_preprocessors.py       |  1 -
 3 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/bob/bio/face/config/preprocessor/face_detect.py b/bob/bio/face/config/preprocessor/face_detect.py
index c30eb351..1b6e0d4d 100644
--- a/bob/bio/face/config/preprocessor/face_detect.py
+++ b/bob/bio/face/config/preprocessor/face_detect.py
@@ -1,16 +1,15 @@
 #!/usr/bin/env python
 
 import bob.bio.face
-import functools
 
 # Detects the face and eye landmarks crops it using the detected eyes
-preprocessor = functools.partial(bob.bio.face.preprocessor.FaceDetect,
+preprocessor = bob.bio.face.preprocessor.FaceDetect(
   face_cropper = 'face-crop-eyes',
   use_flandmark = True
 )
 
 # Detects the face amd crops it without eye detection
-preprocessor_no_eyes = functools.partial(bob.bio.face.preprocessor.FaceDetect,
+preprocessor_no_eyes = bob.bio.face.preprocessor.FaceDetect(
   face_cropper = 'face-crop-eyes',
   use_flandmark = False
 )
diff --git a/bob/bio/face/preprocessor/utils.py b/bob/bio/face/preprocessor/utils.py
index 8c54e954..2a7ccdcf 100644
--- a/bob/bio/face/preprocessor/utils.py
+++ b/bob/bio/face/preprocessor/utils.py
@@ -1,36 +1,37 @@
 import bob.bio.base
 import six
 
-import functools
-
 
 def load_cropper(face_cropper):
-  from .FaceCrop import FaceCrop
-  from .FaceDetect import FaceDetect
-  if face_cropper is None:
-    cropper = None
-  elif isinstance(face_cropper, six.string_types):
-    cropper = bob.bio.base.load_resource(face_cropper, 'preprocessor')
-  # In Dask, face_cropper is a functools. TODO: check that the object inside functool is valid
-  elif isinstance(face_cropper, (FaceCrop, FaceDetect, functools.partial)):
-    cropper = face_cropper
-  else:
-    raise ValueError("The given face cropper type is not understood")
-
-  assert cropper is None or isinstance(cropper,  (FaceCrop, FaceDetect)) or isinstance(cropper, functools.partial)
-  return cropper
+    from .FaceCrop import FaceCrop
+    from .FaceDetect import FaceDetect
+
+    if face_cropper is None:
+        cropper = None
+    elif isinstance(face_cropper, six.string_types):
+        cropper = bob.bio.base.load_resource(face_cropper, "preprocessor")
+    else:
+        raise ValueError("The given face cropper type is not understood")
+
+    assert (
+        cropper is None
+        or isinstance(cropper, (FaceCrop, FaceDetect))
+        or isinstance(cropper, functools.partial)
+    )
+    return cropper
 
 
 def load_cropper_only(face_cropper):
-  from .FaceCrop import FaceCrop
-  if face_cropper is None:
-    cropper = None
-  elif isinstance(face_cropper, six.string_types):
-    cropper = bob.bio.base.load_resource(face_cropper, 'preprocessor')
-  elif isinstance(face_cropper, FaceCrop):
-    cropper = face_cropper
-  else:
-    raise ValueError("The given face cropper type is not understood")
-
-  assert cropper is None or isinstance(cropper, FaceCrop)
-  return cropper
+    from .FaceCrop import FaceCrop
+
+    if face_cropper is None:
+        cropper = None
+    elif isinstance(face_cropper, six.string_types):
+        cropper = bob.bio.base.load_resource(face_cropper, "preprocessor")
+    elif isinstance(face_cropper, FaceCrop):
+        cropper = face_cropper
+    else:
+        raise ValueError("The given face cropper type is not understood")
+
+    assert cropper is None or isinstance(cropper, FaceCrop)
+    return cropper
diff --git a/bob/bio/face/test/test_preprocessors.py b/bob/bio/face/test/test_preprocessors.py
index 634a495a..ffdf8384 100644
--- a/bob/bio/face/test/test_preprocessors.py
+++ b/bob/bio/face/test/test_preprocessors.py
@@ -119,7 +119,6 @@ def test_face_crop():
 
 def test_face_detect():
   image, annotation = _image(), None
-
   cropper = bob.bio.base.load_resource('face-detect', 'preprocessor', preferred_package='bob.bio.face')
   assert isinstance(cropper, bob.bio.face.preprocessor.FaceDetect)
   assert isinstance(cropper, bob.bio.face.preprocessor.Base)
-- 
GitLab