From f0ffe1978cb57a40c89fa01c11331761843cfc27 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Mon, 3 Jun 2024 20:10:28 +0100 Subject: [PATCH 1/5] whitespaces removed --- deepface/DeepFace.py | 2 +- deepface/modules/verification.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index fdee7e1..159dcb4 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -300,7 +300,7 @@ def find( silent (boolean): Suppress or allow some log messages for a quieter analysis process (default is False). - refresh_database (boolean): Synchronizes the images representation (pkl) file with the + refresh_database (boolean): Synchronizes the images representation (pkl) file with the directory/db files, if set to false, it will ignore any file changes inside the db_path (default is True). diff --git a/deepface/modules/verification.py b/deepface/modules/verification.py index 725f099..5727ef3 100644 --- a/deepface/modules/verification.py +++ b/deepface/modules/verification.py @@ -64,7 +64,7 @@ def verify( silent (boolean): Suppress or allow some log messages for a quieter analysis process (default is False). - + threshold (float): Specify a threshold to determine whether a pair represents the same person or different individuals. This threshold is used for comparing distances. If left unset, default pre-tuned threshold values will be applied based on the specified From 0538c207b013ea1df05141bbd1e5bdd0d7c325e6 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Mon, 3 Jun 2024 20:10:51 +0100 Subject: [PATCH 2/5] docker hub info added --- README.md | 4 ++-- scripts/dockerize.sh | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6ec645a..13c766f 100644 --- a/README.md +++ b/README.md @@ -319,6 +319,8 @@ Face recognition, facial attribute analysis and vector representation functions **Dockerized Service** - [`Demo`](https://youtu.be/9Tk9lRQareA) +[![Docker Pulls](https://img.shields.io/docker/pulls/serengil/deepface?logo=docker)](https://hub.docker.com/r/serengil/deepface) + You can deploy the deepface api on a kubernetes cluster with docker. The following [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh) will serve deepface on `localhost:5005`. You may need to re-configure the [Dockerfile](https://github.com/serengil/deepface/blob/master/Dockerfile) if you want to apply some customization. Then, even if you do not have a development environment, you will be able to consume deepface services such as verify and analyze. You can also access the inside of the docker image to run deepface related commands. Please follow the instructions in the [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh). ```shell @@ -326,8 +328,6 @@ cd scripts ./dockerize.sh ``` -

- **Command Line Interface** - [`Demo`](https://youtu.be/PKKTAr3ts2s) DeepFace comes with a command line interface as well. You are able to access its functions in command line as shown below. The command deepface expects the function name as 1st argument and function arguments thereafter. diff --git a/scripts/dockerize.sh b/scripts/dockerize.sh index 2bd22d4..f29bed7 100644 --- a/scripts/dockerize.sh +++ b/scripts/dockerize.sh @@ -16,10 +16,14 @@ docker build -t deepface . # copy weights from your local # docker cp ~/.deepface/weights/. :/root/.deepface/weights/ -# run image +# run the built image # docker run --net="host" deepface docker run -p 5005:5000 deepface +# or pull the pre-built image from docker hub and run it +# docker pull serengil/deepface +# docker run -p 5005:5000 serengil/deepface + # to access the inside of docker image when it is in running status # docker exec -it /bin/sh From 13d502d3d80c24220a4b329ecfa5a0639a33df29 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Mon, 3 Jun 2024 20:11:20 +0100 Subject: [PATCH 3/5] unit test added for facial area coordinates after adding borders --- tests/test_extract_faces.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_extract_faces.py b/tests/test_extract_faces.py index eac1e82..0ddd9d5 100644 --- a/tests/test_extract_faces.py +++ b/tests/test_extract_faces.py @@ -2,6 +2,7 @@ import base64 # 3rd party dependencies +import cv2 import numpy as np import pytest @@ -16,8 +17,12 @@ detectors = ["opencv", "mtcnn"] def test_different_detectors(): + img_path = "dataset/img11.jpg" + img = cv2.imread(img_path) + height, width, _ = img.shape + for detector in detectors: - img_objs = DeepFace.extract_faces(img_path="dataset/img11.jpg", detector_backend=detector) + img_objs = DeepFace.extract_faces(img_path=img_path, detector_backend=detector) for img_obj in img_objs: assert "face" in img_obj.keys() assert "facial_area" in img_obj.keys() @@ -34,6 +39,23 @@ def test_different_detectors(): assert left_eye[0] > right_eye[0] assert "confidence" in img_obj.keys() + # we added black pixeled borders to image because if faces are close to border, + # then alignment moves them to outside of the image. adding this borders may + # cause to miscalculate the facial area. check it is restored correctly. + x = img_obj["facial_area"]["x"] + y = img_obj["facial_area"]["y"] + w = img_obj["facial_area"]["w"] + h = img_obj["facial_area"]["h"] + + assert x < width + assert x + w < width + assert y < height + assert y + h < height + assert left_eye[0] < height + assert right_eye[0] < height + assert left_eye[1] < width + assert right_eye[1] < width + img = img_obj["face"] assert img.shape[0] > 0 and img.shape[1] > 0 logger.info(f"✅ extract_faces for {detector} backend test is done") From d4ea9ce364134c01dffce456e679ca0c03e21513 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Mon, 3 Jun 2024 20:13:22 +0100 Subject: [PATCH 4/5] docker stock image removed accidentially --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 13c766f..9069f4d 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,8 @@ cd scripts ./dockerize.sh ``` +

+ **Command Line Interface** - [`Demo`](https://youtu.be/PKKTAr3ts2s) DeepFace comes with a command line interface as well. You are able to access its functions in command line as shown below. The command deepface expects the function name as 1st argument and function arguments thereafter. From cb448d6d5f6e999890f109e7c03414663123de72 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Mon, 3 Jun 2024 20:19:05 +0100 Subject: [PATCH 5/5] use docker hub by default --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9069f4d..81e1cd8 100644 --- a/README.md +++ b/README.md @@ -321,11 +321,11 @@ Face recognition, facial attribute analysis and vector representation functions [![Docker Pulls](https://img.shields.io/docker/pulls/serengil/deepface?logo=docker)](https://hub.docker.com/r/serengil/deepface) -You can deploy the deepface api on a kubernetes cluster with docker. The following [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh) will serve deepface on `localhost:5005`. You may need to re-configure the [Dockerfile](https://github.com/serengil/deepface/blob/master/Dockerfile) if you want to apply some customization. Then, even if you do not have a development environment, you will be able to consume deepface services such as verify and analyze. You can also access the inside of the docker image to run deepface related commands. Please follow the instructions in the [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh). +The following command set will serve deepface on `localhost:5005` via docker. Then, you will be able to consume deepface services such as verify, analyze and represent. Also, if you want to build the image by your own instead of pre-built image from docker hub, [Dockerfile](https://github.com/serengil/deepface/blob/master/Dockerfile) is available in the root folder of the project. ```shell -cd scripts -./dockerize.sh +docker pull serengil/deepface +docker run -p 5005:5000 serengil/deepface ```