Skip to content

Commit

Permalink
fix(represent): change somthing according to comments and adapt pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei committed Dec 14, 2023
1 parent 8c6dad0 commit 7b1451a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length=100"],
"editor.fontWeight": "normal",
"python.analysis.extraPaths": ["./deepface"]
"python.analysis.extraPaths": [
"./deepface"
],
"black-formatter.args": [
"--line-length=100"
]
}
28 changes: 13 additions & 15 deletions deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,16 @@ def represent(
{
// Multidimensional vector
// The number of dimensions is changing based on the reference model.
// E.g. FaceNet returns 128 dimensional vector; VGG-Face returns 2622 dimensional vector.
"embedding": np.array,
// E.g. FaceNet returns 128 dimensional vector;
// VGG-Face returns 2622 dimensional vector.
"embedding": np.array,
// Detected Facial-Area by Face detection in dict format.
// (x, y) is left-corner point, and (w, h) is the width and height
// If `detector_backend` == `skip`, it is the full image area and nonsense.
"facial_area": dict{"x": int, "y": int, "w": int, "h": int},
// Face detection confidence.
// Face detection confidence.
// If `detector_backend` == `skip`, will be 0 and nonsense.
"face_confidence": float
}
Expand All @@ -716,23 +717,20 @@ def represent(
align=align,
)
else: # skip
if type(img_path).__module__ == np.__name__:
img = img_path.copy()
else:
# Try load. If load error, will raise exception internal
img, _ = functions.load_image(img_path)
# Try load. If load error, will raise exception internal
img, _ = functions.load_image(img_path)
# --------------------------------
if len(img.shape) == 4:
img = img[0] # e.g. (1, 224, 224, 3) to (224, 224, 3)
if len(img.shape) == 3:
img = cv2.resize(img, target_size)
img = np.expand_dims(img, axis=0) # Why we remove a axis=0 previously and here expand one?
# when represent is called from verify, this is already normalized. But needed when user given.
img = np.expand_dims(img, axis=0)
# when called from verify, this is already normalized. But needed when user given.
if img.max() > 1:
img = img.astype(np.float32) / 255.
img = img.astype(np.float32) / 255.0
# --------------------------------
# make dummy region and confidence to keep compatibility with `extract_faces`
img_region = {"x": 0, "y": 0, "w": img.shape[1], "h": img.shape[2]}
img_region = {"x": 0, "y": 0, "w": img.shape[1], "h": img.shape[2]}
img_objs = [(img, img_region, 0)]
# ---------------------------------

Expand All @@ -746,7 +744,7 @@ def represent(
# embedding = model.predict(img, verbose=0)[0].tolist()
embedding = model(img, training=False).numpy()[0].tolist()
# if you still get verbose logging. try call
# - `tf.keras.utils.disable_interactive_logging()`
# - `tf.keras.utils.disable_interactive_logging()`
# in your main program
else:
# SFace and Dlib are not keras models and no verbose arguments
Expand Down
9 changes: 2 additions & 7 deletions deepface/commons/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,8 @@ def load_image(img):
if type(img).__module__ == np.__name__:
return img, None

try:
# Test whether img is a Python3's Path. If hit, tranform to str to let following logic work.
from pathlib import Path
if isinstance(img, Path):
img = str(img)
except ImportError:
pass
if isinstance(img, Path):
img = str(img)

# The image is a base64 string
if img.startswith("data:image/"):
Expand Down

0 comments on commit 7b1451a

Please sign in to comment.