Skip to content

Commit

Permalink
dockerized service
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Jan 5, 2023
1 parent 531522f commit 0f3db24
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
45 changes: 36 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
#base image
FROM python:3.8

LABEL org.opencontainers.image.source https://github.com/serengil/deepface

COPY . .

# -----------------------------------
# create required folder
RUN mkdir /app
RUN mkdir /app/api
RUN mkdir /app/deepface
# -----------------------------------
# Copy required files from repo into image
COPY ./deepface /app/deepface
COPY ./api/api.py /app/
COPY ./setup.py /app/
COPY ./README.md /app/
# -----------------------------------
# switch to application directory
WORKDIR /app
# -----------------------------------
# update image os
RUN apt-get update

RUN apt-get install ffmpeg libsm6 libxext6 -y

RUN pip install .

CMD ["deepface", "--help"]
# -----------------------------------
# install deepface from pypi release (might be out-of-the-date)
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org deepface
# -----------------------------------
# install deepface from source code (always up-to-date)
RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org -e .
# -----------------------------------
# some packages are optional in deepface. activate if your task depends on one.
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org cmake==3.24.1.1
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org dlib==19.20.0
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org lightgbm==2.3.1
# -----------------------------------
# environment variables
ENV PYTHONUNBUFFERED=1
# -----------------------------------
# run the app (re-configure port if necessary)
EXPOSE 5000
# flask run is not recommended in production, move this to gunicorn
CMD ["python", "/app/api.py", "--port", "5000"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ python api.py

Face recognition, facial attribute analysis and vector representation functions are covered in the API. You are expected to call these functions as http post methods. Service endpoints will be `http://127.0.0.1:5000/verify` for face recognition, `http://127.0.0.1:5000/analyze` for facial attribute analysis, and `http://127.0.0.1:5000/represent` for vector representation. You should pass input images as base64 encoded string in this case. [Here](https://github.com/serengil/deepface/tree/master/api), you can find a postman project.

**Dockerized Service**

You can deploy the deepface api on a kubernetes cluster with docker. The following shell script will serve deepface on localhost:5000. You need to re-configure the Dockerfile if you want to change the port. Then, even if you do not have a development environment, you will be able to consume deepface services. You can also access the inside of the docker image to run deepface related commands. Please follow the instructions in the shell script.

```shell
cd scripts
./dockerize.sh
```

**Command Line Interface**

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.
Expand Down
20 changes: 19 additions & 1 deletion scripts/dockerize.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# start docker
# sudo service docker start

# list current docker packages
# docker container ls -a

# delete existing deepface packages
# docker rm -f $(docker ps -a -q --filter "ancestor=deepface")

# build deepface image
docker build -t deepface_image .

docker run -it deepface_image /bin/sh
# run image
docker run --net="host" deepface

# to access the inside of docker image when it is in running status
# docker run -it --net="host" deepface /bin/sh

# healthcheck
# sleep 3s
# curl localhost:5000

0 comments on commit 0f3db24

Please sign in to comment.