Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat task 1002 facial area coordinates bug for dlib #1020

Merged
merged 5 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ipynb linguist-vendored
1 change: 1 addition & 0 deletions deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
detection,
realtime,
)
from deepface import __version__

logger = Logger(module="DeepFace")

Expand Down
1 change: 1 addition & 0 deletions deepface/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.85"
12 changes: 7 additions & 5 deletions deepface/detectors/Dlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ def detect_faces(
top = d.top()
bottom = d.bottom()

# detected_face = img[top:bottom, left:right]
detected_face = img[
max(0, top) : min(bottom, img.shape[0]), max(0, left) : min(right, img.shape[1])
]
y = int(max(0, top))
h = int(min(bottom, img.shape[0]) - y)
x = int(max(0, left))
w = int(min(right, img.shape[1]) - x)

img_region = FacialAreaRegion(x=left, y=right, w=right - left, h=bottom - top)
detected_face = img[int(y) : int(y + h), int(x) : int(x + w)]

img_region = FacialAreaRegion(x=x, y=y, w=w, h=h)
confidence = scores[idx]

if align:
Expand Down
33 changes: 33 additions & 0 deletions deepface/modules/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ def verify(
def find_cosine_distance(
source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list]
) -> np.float64:
"""
Find cosine distance between two given vectors
Args:
source_representation (np.ndarray or list): 1st vector
test_representation (np.ndarray or list): 2nd vector
Returns
distance (np.float64): calculated cosine distance
"""
if isinstance(source_representation, list):
source_representation = np.array(source_representation)

Expand All @@ -190,6 +198,14 @@ def find_cosine_distance(
def find_euclidean_distance(
source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list]
) -> np.float64:
"""
Find euclidean distance between two given vectors
Args:
source_representation (np.ndarray or list): 1st vector
test_representation (np.ndarray or list): 2nd vector
Returns
distance (np.float64): calculated euclidean distance
"""
if isinstance(source_representation, list):
source_representation = np.array(source_representation)

Expand All @@ -203,12 +219,29 @@ def find_euclidean_distance(


def l2_normalize(x: Union[np.ndarray, list]) -> np.ndarray:
"""
Normalize input vector with l2
Args:
x (np.ndarray or list): given vector
Returns:
y (np.ndarray): l2 normalized vector
"""
if isinstance(x, list):
x = np.array(x)
return x / np.sqrt(np.sum(np.multiply(x, x)))


def find_threshold(model_name: str, distance_metric: str) -> float:
"""
Retrieve pre-tuned threshold values for a model and distance metric pair
Args:
model_name (str): facial recognition model name
distance_metric (str): distance metric name. Options are cosine, euclidean
and euclidean_l2.
Returns:
threshold (float): threshold value for that model name and distance metric
pair. Distances less than this threshold will be classified same person.
"""

base_threshold = {"cosine": 0.40, "euclidean": 0.55, "euclidean_l2": 0.75}

Expand Down
3 changes: 3 additions & 0 deletions package_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "0.0.85"
}
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import setuptools

with open("README.md", "r", encoding="utf-8") as fh:
Expand All @@ -6,16 +7,19 @@
with open("requirements.txt", "r", encoding="utf-8") as f:
requirements = f.read().split("\n")

with open("package_info.json", "r", encoding="utf-8") as f:
package_info = json.load(f)

setuptools.setup(
name="deepface",
version="0.0.85",
version=package_info["version"],
author="Sefik Ilkin Serengil",
author_email="[email protected]",
description=(
"A Lightweight Face Recognition and Facial Attribute Analysis Framework"
" (Age, Gender, Emotion, Race) for Python"
),
data_files=[("", ["README.md", "requirements.txt"])],
data_files=[("", ["README.md", "requirements.txt", "package_info.json"])],
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/serengil/deepface",
Expand Down
13 changes: 13 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json
from deepface import DeepFace
from deepface.commons.logger import Logger

logger = Logger("tests/test_version.py")


def test_version():
with open("../package_info.json", "r", encoding="utf-8") as f:
package_info = json.load(f)

assert DeepFace.__version__ == package_info["version"]
logger.info("✅ versions are matching in both package_info.json and deepface/__init__.py")
Loading