From 6f188ce9d4166923eefa37a363f96ae09d900595 Mon Sep 17 00:00:00 2001
From: Manuel Guenther <guenther@ifi.uzh.ch>
Date: Wed, 15 Feb 2023 16:56:37 +0100
Subject: [PATCH] Got files automatically formatted

---
 src/bob/bio/face/preprocessor/croppers.py |  4 +-
 src/bob/bio/face/utils.py                 | 21 ++++---
 tests/test_preprocessors.py               | 69 ++++++++++++++++-------
 3 files changed, 62 insertions(+), 32 deletions(-)

diff --git a/src/bob/bio/face/preprocessor/croppers.py b/src/bob/bio/face/preprocessor/croppers.py
index 416ed605..11384351 100644
--- a/src/bob/bio/face/preprocessor/croppers.py
+++ b/src/bob/bio/face/preprocessor/croppers.py
@@ -110,7 +110,9 @@ class FaceEyesNorm(TransformerMixin, BaseEstimator):
         elif self.annotation_type == "right-profile":
             return np.array(positions["reye"]), np.array(positions["mouth"])
         elif self.annotation_type == "bounding-box":
-            return np.array(positions["topleft"]), np.array(positions["bottomright"])
+            return np.array(positions["topleft"]), np.array(
+                positions["bottomright"]
+            )
         else:
             raise ValueError(
                 "The annotation type must be either 'eyes-center', 'left-profile', 'right-profile' or 'bounding-box'"
diff --git a/src/bob/bio/face/utils.py b/src/bob/bio/face/utils.py
index d50ced55..9a095a40 100644
--- a/src/bob/bio/face/utils.py
+++ b/src/bob/bio/face/utils.py
@@ -403,19 +403,19 @@ def face_crop_solver(
     else:
         # Detects the face and crops it without eye detection
 
-        if isinstance(cropped_positions, (list,tuple)):
+        if isinstance(cropped_positions, (list, tuple)):
             # TODO: This is a hack to support multiple annotations for left, right and eyes center profile
             # We need to do a more elegant solution
 
             croppers = []
             for positions in cropped_positions:
                 cropper = face_crop_solver(
-                        cropped_image_size=cropped_image_size,
-                        cropped_positions=positions,
-                        fixed_positions=fixed_positions,
-                        color_channel=color_channel,
-                        annotator=annotator,
-                        dtype=dtype,
+                    cropped_image_size=cropped_image_size,
+                    cropped_positions=positions,
+                    fixed_positions=fixed_positions,
+                    color_channel=color_channel,
+                    annotator=annotator,
+                    dtype=dtype,
                 )
                 croppers.append(cropper)
 
@@ -423,18 +423,17 @@ def face_crop_solver(
                 return croppers[0]
             return MultiFaceCrop(croppers)
         else:
-
             face_norm = FaceEyesNorm(
                 cropped_positions,
                 cropped_image_size,
                 annotation_type=_solve_annotation_type(cropped_positions),
             )
             # If the eyes annotations are provided
-            if ("topleft" in cropped_positions
+            if (
+                "topleft" in cropped_positions
                 and "bottomright" in cropped_positions
                 and len(cropped_positions) >= 4
             ):
-
                 return BoundingBoxAnnotatorCrop(
                     eyes_cropper=face_norm,
                     annotator=annotator,
@@ -448,7 +447,7 @@ def face_crop_solver(
                     fixed_positions=fixed_positions,
                     dtype=dtype,
                     annotator=annotator,
-                    cropper=face_norm
+                    cropper=face_norm,
                 )
 
 
diff --git a/tests/test_preprocessors.py b/tests/test_preprocessors.py
index dda4c9f3..22bb11d1 100644
--- a/tests/test_preprocessors.py
+++ b/tests/test_preprocessors.py
@@ -111,8 +111,6 @@ def test_base():
 def test_face_crop_solver():
     # tests that the face crop solver returns the right things
 
-    image, annotation = _image(), _annotation()
-
     # test default croppers
     eyes_norm = bob.bio.face.utils.face_crop_solver(
         cropped_image_size=(CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
@@ -125,32 +123,53 @@ def test_face_crop_solver():
         cropped_image_size=(CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
         cropped_positions={"leye": LEFT_EYE_POS, "mouth": RIGHT_EYE_POS},
     )
-    assert isinstance(left_profile_norm.cropper, bob.bio.face.preprocessor.FaceEyesNorm)
+    assert isinstance(
+        left_profile_norm.cropper, bob.bio.face.preprocessor.FaceEyesNorm
+    )
     assert left_profile_norm.cropper.annotation_type == "left-profile"
 
     right_profile_norm = bob.bio.face.utils.face_crop_solver(
         cropped_image_size=(CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
         cropped_positions={"reye": LEFT_EYE_POS, "mouth": RIGHT_EYE_POS},
     )
-    assert isinstance(right_profile_norm.cropper, bob.bio.face.preprocessor.FaceEyesNorm)
+    assert isinstance(
+        right_profile_norm.cropper, bob.bio.face.preprocessor.FaceEyesNorm
+    )
     assert right_profile_norm.cropper.annotation_type == "right-profile"
 
     bounding_box_norm = bob.bio.face.utils.face_crop_solver(
         cropped_image_size=(CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
-        cropped_positions={"topleft": (0,0), "bottomright": eyes_norm.cropped_image_size},
+        cropped_positions={
+            "topleft": (0, 0),
+            "bottomright": eyes_norm.cropped_image_size,
+        },
+    )
+    assert isinstance(
+        bounding_box_norm.cropper, bob.bio.face.preprocessor.FaceEyesNorm
     )
-    assert isinstance(bounding_box_norm.cropper, bob.bio.face.preprocessor.FaceEyesNorm)
     assert bounding_box_norm.cropper.annotation_type == "bounding-box"
 
     # test bounding box cropper with detection
     bbx_annotator_norm = bob.bio.face.utils.face_crop_solver(
         (CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
-        cropped_positions={"leye": LEFT_EYE_POS, "reye": RIGHT_EYE_POS, "topleft": (0,0), "bottomright": eyes_norm.cropped_image_size},
+        cropped_positions={
+            "leye": LEFT_EYE_POS,
+            "reye": RIGHT_EYE_POS,
+            "topleft": (0, 0),
+            "bottomright": eyes_norm.cropped_image_size,
+        },
+    )
+    assert isinstance(
+        bbx_annotator_norm, bob.bio.face.preprocessor.BoundingBoxAnnotatorCrop
+    )
+    assert isinstance(
+        bbx_annotator_norm.eyes_cropper, bob.bio.face.preprocessor.FaceEyesNorm
     )
-    assert isinstance(bbx_annotator_norm, bob.bio.face.preprocessor.BoundingBoxAnnotatorCrop)
-    assert isinstance(bbx_annotator_norm.eyes_cropper, bob.bio.face.preprocessor.FaceEyesNorm)
     assert bbx_annotator_norm.eyes_cropper.annotation_type == "eyes-center"
-    assert isinstance(bbx_annotator_norm.face_cropper, bob.bio.face.preprocessor.FaceCropBoundingBox)
+    assert isinstance(
+        bbx_annotator_norm.face_cropper,
+        bob.bio.face.preprocessor.FaceCropBoundingBox,
+    )
 
     # test multi cropper
     multi_norm = bob.bio.face.utils.face_crop_solver(
@@ -159,16 +178,21 @@ def test_face_crop_solver():
             {"leye": LEFT_EYE_POS, "reye": RIGHT_EYE_POS},
             {"leye": LEFT_EYE_POS, "mouth": RIGHT_EYE_POS},
             {"reye": LEFT_EYE_POS, "mouth": RIGHT_EYE_POS},
-            {"topleft": (0,0), "bottomright": eyes_norm.cropped_image_size},
-        )
+            {"topleft": (0, 0), "bottomright": eyes_norm.cropped_image_size},
+        ),
     )
 
     assert isinstance(multi_norm, bob.bio.face.preprocessor.MultiFaceCrop)
     assert isinstance(multi_norm.croppers_list, list)
     assert len(multi_norm.croppers_list) == 4
-    assert all(isinstance(cropper,bob.bio.face.preprocessor.FaceCrop) for cropper in multi_norm.croppers_list)
-    assert all(isinstance(cropper.cropper,bob.bio.face.preprocessor.FaceEyesNorm) for cropper in multi_norm.croppers_list)
-
+    assert all(
+        isinstance(cropper, bob.bio.face.preprocessor.FaceCrop)
+        for cropper in multi_norm.croppers_list
+    )
+    assert all(
+        isinstance(cropper.cropper, bob.bio.face.preprocessor.FaceEyesNorm)
+        for cropper in multi_norm.croppers_list
+    )
 
 
 def test_face_crop():
@@ -225,7 +249,9 @@ def test_face_crop():
     # reset the configuration, so that later tests don't get screwed.
     cropper.color_channel = "gray"
 
-    cropped_positions = dict(topleft=(0,0), bottomright=cropper.cropped_image_size)
+    cropped_positions = dict(
+        topleft=(0, 0), bottomright=cropper.cropped_image_size
+    )
     # check cropping based on bounding box
     bbx_cropper = bob.bio.face.preprocessor.FaceCrop(
         cropper.cropped_image_size,
@@ -235,11 +261,15 @@ def test_face_crop():
             cropper.cropped_image_size,
             annotation_type="bounding-box",
         ),
-        dtype=int
+        dtype=int,
+    )
+    reference = pkg_resources.resource_filename(
+        __name__, "data/boundingboxed.hdf5"
     )
-    reference = pkg_resources.resource_filename(__name__, "data/boundingboxed.hdf5")
 
-    annot = dict(topleft=annotation["topleft"], bottomright=annotation["bottomright"])
+    annot = dict(
+        topleft=annotation["topleft"], bottomright=annotation["bottomright"]
+    )
     _compare(bbx_cropper.transform([image], [annot])[0], reference)
 
 
@@ -248,7 +278,6 @@ class FakeAnnotator(bob.bio.face.annotator.Base):
         return None
 
 
-
 @is_library_available("tensorflow")
 def test_bounding_box_annotator_crop():
     # read input
-- 
GitLab