aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/reader/face.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsie/reader/face.py')
-rw-r--r--bsie/reader/face.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/bsie/reader/face.py b/bsie/reader/face.py
index e43b93f..5e38101 100644
--- a/bsie/reader/face.py
+++ b/bsie/reader/face.py
@@ -1,6 +1,5 @@
# standard imports
-import operator
import typing
# external imports
@@ -9,7 +8,7 @@ import PIL.Image
import torch
# bsie imports
-from bsie.utils import bsfs, errors, ns
+from bsie.utils import bsfs, errors
# inner-module imports
from . import base
@@ -44,9 +43,9 @@ class FaceExtract(base.Reader):
min_face_prob: float = 0.992845,
cuda_device: str = 'cuda:0',
ext_face_size: int = 160,
- thresholds: typing.Tuple[float, float, float] = [0.5, 0.6, 0.6],
+ thresholds: typing.Tuple[float, float, float] = (0.5, 0.6, 0.6),
factor: float = 0.709,
- ):
+ ): # pylint: disable=too-many-arguments
# initialize
self._device = torch.device(cuda_device if torch.cuda.is_available() else 'cpu')
# initialize the face detection network
@@ -81,7 +80,9 @@ class FaceExtract(base.Reader):
img: PIL.Image.Image,
target_size: int,
rotate: typing.Union[bool, int] = True,
- ) -> typing.Tuple[PIL.Image.Image, typing.Callable[[typing.Tuple[float, float]], typing.Tuple[float, float]]]:
+ ) -> typing.Tuple[
+ PIL.Image.Image,
+ typing.Callable[[typing.Tuple[float, float]], typing.Tuple[float, float]]]:
"""Preprocess an image. Return the image and a coordinate back-transformation function.
1. Scale larger side to *target_size*
2. Rotate by angle *rotate*, or auto-rotate if *rotate=None* (the default).
@@ -106,23 +107,23 @@ class FaceExtract(base.Reader):
), reducing_gap=3)
# get scale factors
- sX = orig_size[0] / img.width
- sY = orig_size[1] / img.height
+ scale_x = orig_size[0] / img.width
+ scale_y = orig_size[1] / img.height
# rotate image (if need be)
- denorm = lambda xy: (sX*xy[0], sY*xy[1])
+ denorm = lambda xy: (scale_x*xy[0], scale_y*xy[1])
if rotate is not None:
# auto-rotate according to EXIF information
img_ori = img.getexif().get(exif_ori, None)
if img_ori == 3 or rotate == 180:
img = img.rotate(180, expand=True)
- denorm = lambda xy: (orig_size[0] - sX*xy[0], orig_size[1] - sY*xy[1])
+ denorm = lambda xy: (orig_size[0] - scale_x*xy[0], orig_size[1] - scale_y*xy[1])
elif img_ori == 6 or rotate == 270:
img = img.rotate(270, expand=True)
- denorm = lambda xy: (orig_size[0] - sX*xy[1], sY*xy[0])
+ denorm = lambda xy: (orig_size[0] - scale_x*xy[1], scale_y*xy[0])
elif img_ori == 8 or rotate == 90:
img = img.rotate(90, expand=True)
- denorm = lambda xy: (sX*xy[1], orig_size[1] - sY*xy[0])
+ denorm = lambda xy: (scale_x*xy[1], orig_size[1] - scale_y*xy[0])
# return image and denormalization function
return img, denorm