Merge pull request #1249 from serengil/feat-task-0306-docker-hub

Feat task 0306 docker hub
This commit is contained in:
Sefik Ilkin Serengil 2024-06-03 21:01:27 +01:00 committed by GitHub
commit b1661fb72d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 7 deletions

View File

@ -319,11 +319,13 @@ Face recognition, facial attribute analysis and vector representation functions
**Dockerized Service** - [`Demo`](https://youtu.be/9Tk9lRQareA)
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).
[![Docker Pulls](https://img.shields.io/docker/pulls/serengil/deepface?logo=docker)](https://hub.docker.com/r/serengil/deepface)
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
```
<p align="center"><img src="https://raw.githubusercontent.com/serengil/deepface/master/icon/deepface-dockerized-v2.jpg" width="50%" height="50%"></p>

View File

@ -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).

View File

@ -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

View File

@ -16,10 +16,14 @@ docker build -t deepface .
# copy weights from your local
# docker cp ~/.deepface/weights/. <CONTAINER_ID>:/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 <CONTAINER_ID> /bin/sh

View File

@ -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")