mirror of
https://github.com/serengil/deepface.git
synced 2025-07-23 18:30:04 +00:00
Reformat with black and pylint.
This commit is contained in:
parent
0d176360ad
commit
3a325f5540
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@ -6,12 +6,8 @@
|
|||||||
"editor.renderWhitespace": "all",
|
"editor.renderWhitespace": "all",
|
||||||
"files.autoSave": "afterDelay",
|
"files.autoSave": "afterDelay",
|
||||||
"python.analysis.typeCheckingMode": "basic",
|
"python.analysis.typeCheckingMode": "basic",
|
||||||
"python.formatting.provider": "black",
|
"python.formatting.provider": "autopep8",
|
||||||
"python.formatting.blackArgs": [
|
"python.formatting.blackArgs": ["--line-length=100"],
|
||||||
"--line-length=100"
|
|
||||||
],
|
|
||||||
"editor.fontWeight": "normal",
|
"editor.fontWeight": "normal",
|
||||||
"python.analysis.extraPaths": [
|
"python.analysis.extraPaths": ["./deepface"]
|
||||||
"./deepface"
|
|
||||||
]
|
|
||||||
}
|
}
|
@ -85,30 +85,26 @@ def load_image(img):
|
|||||||
Returns:
|
Returns:
|
||||||
numpy array: the loaded image.
|
numpy array: the loaded image.
|
||||||
"""
|
"""
|
||||||
exact_image = False
|
|
||||||
|
|
||||||
# The image is already a numpy array
|
# The image is already a numpy array
|
||||||
if type(img).__module__ == np.__name__:
|
if type(img).__module__ == np.__name__:
|
||||||
# exact_image = True
|
|
||||||
return img
|
return img
|
||||||
|
|
||||||
# The image is a base64 string
|
# The image is a base64 string
|
||||||
elif img.startswith("data:image/"):
|
if img.startswith("data:image/"):
|
||||||
return loadBase64Img(img)
|
return loadBase64Img(img)
|
||||||
|
|
||||||
# The image is a url
|
# The image is a url
|
||||||
elif img.startswith("http"):
|
if img.startswith("http"):
|
||||||
return np.array(Image.open(requests.get(img, stream=True, timeout=60).raw).convert("RGB"))[:, :, ::-1]
|
return np.array(
|
||||||
|
Image.open(requests.get(img, stream=True, timeout=60).raw).convert("RGB")
|
||||||
|
)[:, :, ::-1]
|
||||||
|
|
||||||
# The image is a path
|
# The image is a path
|
||||||
if exact_image is not True: # image path passed as input
|
|
||||||
if os.path.isfile(img) is not True:
|
if os.path.isfile(img) is not True:
|
||||||
raise ValueError(f"Confirm that {img} exists")
|
raise ValueError(f"Confirm that {img} exists")
|
||||||
|
|
||||||
return cv2.imread(img)
|
return cv2.imread(img)
|
||||||
|
|
||||||
return img
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
@ -125,9 +121,11 @@ def extract_faces(
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
img: a path, url, base64 or numpy array.
|
img: a path, url, base64 or numpy array.
|
||||||
target_size (tuple, optional): the target size of the extracted faces. Defaults to (224, 224).
|
target_size (tuple, optional): the target size of the extracted faces.
|
||||||
|
Defaults to (224, 224).
|
||||||
detector_backend (str, optional): the face detector backend. Defaults to "opencv".
|
detector_backend (str, optional): the face detector backend. Defaults to "opencv".
|
||||||
grayscale (bool, optional): whether to convert the extracted faces to grayscale. Defaults to False.
|
grayscale (bool, optional): whether to convert the extracted faces to grayscale.
|
||||||
|
Defaults to False.
|
||||||
enforce_detection (bool, optional): whether to enforce face detection. Defaults to True.
|
enforce_detection (bool, optional): whether to enforce face detection. Defaults to True.
|
||||||
align (bool, optional): whether to align the extracted faces. Defaults to True.
|
align (bool, optional): whether to align the extracted faces. Defaults to True.
|
||||||
|
|
||||||
@ -150,7 +148,8 @@ def extract_faces(
|
|||||||
else:
|
else:
|
||||||
face_detector = FaceDetector.build_model(detector_backend)
|
face_detector = FaceDetector.build_model(detector_backend)
|
||||||
face_objs = FaceDetector.detect_faces(
|
face_objs = FaceDetector.detect_faces(
|
||||||
face_detector, detector_backend, img, align)
|
face_detector, detector_backend, img, align
|
||||||
|
)
|
||||||
|
|
||||||
# in case of no face found
|
# in case of no face found
|
||||||
if len(face_objs) == 0 and enforce_detection is True:
|
if len(face_objs) == 0 and enforce_detection is True:
|
||||||
@ -164,7 +163,6 @@ def extract_faces(
|
|||||||
|
|
||||||
for current_img, current_region, confidence in face_objs:
|
for current_img, current_region, confidence in face_objs:
|
||||||
if current_img.shape[0] > 0 and current_img.shape[1] > 0:
|
if current_img.shape[0] > 0 and current_img.shape[1] > 0:
|
||||||
|
|
||||||
if grayscale is True:
|
if grayscale is True:
|
||||||
current_img = cv2.cvtColor(current_img, cv2.COLOR_BGR2GRAY)
|
current_img = cv2.cvtColor(current_img, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
@ -175,7 +173,9 @@ def extract_faces(
|
|||||||
factor = min(factor_0, factor_1)
|
factor = min(factor_0, factor_1)
|
||||||
|
|
||||||
dsize = (
|
dsize = (
|
||||||
int(current_img.shape[1] * factor), int(current_img.shape[0] * factor))
|
int(current_img.shape[1] * factor),
|
||||||
|
int(current_img.shape[0] * factor),
|
||||||
|
)
|
||||||
current_img = cv2.resize(current_img, dsize)
|
current_img = cv2.resize(current_img, dsize)
|
||||||
|
|
||||||
diff_0 = target_size[0] - current_img.shape[0]
|
diff_0 = target_size[0] - current_img.shape[0]
|
||||||
@ -194,8 +194,10 @@ def extract_faces(
|
|||||||
else:
|
else:
|
||||||
current_img = np.pad(
|
current_img = np.pad(
|
||||||
current_img,
|
current_img,
|
||||||
((diff_0 // 2, diff_0 - diff_0 // 2),
|
(
|
||||||
(diff_1 // 2, diff_1 - diff_1 // 2)),
|
(diff_0 // 2, diff_0 - diff_0 // 2),
|
||||||
|
(diff_1 // 2, diff_1 - diff_1 // 2),
|
||||||
|
),
|
||||||
"constant",
|
"constant",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -233,7 +235,8 @@ def normalize_input(img, normalization="base"):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
img (numpy array): the input image.
|
img (numpy array): the input image.
|
||||||
normalization (str, optional): the normalization technique. Defaults to "base", for no normalization.
|
normalization (str, optional): the normalization technique. Defaults to "base",
|
||||||
|
for no normalization.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
numpy array: the normalized image.
|
numpy array: the normalized image.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user