Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
99 lines (87 loc) · 5.54 KB
/
Copy pathDockerfile
File metadata and controls
99 lines (87 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# base image
FROM python:3.8.12-slim
LABEL org.opencontainers.image.source https://github.com/serengil/deepface
# -----------------------------------
# create required folder
RUN mkdir -p /app && chown -R 1001:0 /app
RUN mkdir /app/deepface
# -----------------------------------
# switch to application directory
WORKDIR /app
# -----------------------------------
# Copy required files from repo into image
COPY ./deepface /app/deepface
# even though we will use local requirements, this one is required to perform install deepface from source code
COPY ./requirements_base.txt /app/requirements_base.txt
# setup.py reads requirements of the backend engine, api, cli, pandas and grpc extras as well
COPY ./requirements_tf.txt /app/requirements_tf.txt
COPY ./requirements_pytorch.txt /app/requirements_pytorch.txt
COPY ./requirements_api.txt /app/requirements_api.txt
COPY ./requirements_cli.txt /app/requirements_cli.txt
COPY ./requirements_pandas.txt /app/requirements_pandas.txt
COPY ./requirements_grpc.txt /app/requirements_grpc.txt
COPY ./requirements_local /app/requirements_local.txt
COPY ./package_info.json /app/
COPY ./setup.py /app/
COPY ./README.md /app/
COPY ./entrypoint.sh /app/deepface/api/src/entrypoint.sh
# -----------------------------------
# if you plan to use a GPU, you should install the 'tensorflow-gpu' package
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org tensorflow-gpu
# if you plan to use face anti-spoofing, then activate this line
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org torch==2.1.2
# -----------------------------------
# install deepface from pypi release (might be out-of-date)
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org deepface
# -----------------------------------
# install dependencies - deepface with these dependency versions is working
# backend engine is chosen with a build arg: onnx (default), tensorflow or pytorch
# docker build -t deepface . -> onnx
# docker build -t deepface --build-arg BACKEND=tensorflow . -> tensorflow
# docker build -t deepface --build-arg BACKEND=pytorch . -> pytorch
# for pytorch and onnx, tensorflow and its dependent packages are not installed, so
ARG BACKEND=onnx
RUN if [ "$BACKEND" = "tensorflow" ]; then \
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org -r /app/requirements_local.txt && \
# mtcnn depends on opencv-python, which overwrites the cv2 module of
# opencv-contrib-python-headless and requires gui system libraries. keep the headless one only.
pip uninstall -y opencv-python && \
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org --force-reinstall --no-deps $(grep "^opencv-contrib-python-headless==" /app/requirements_local.txt) && \
# onnxruntime depends on sympy for its symbolic shape inference tools only, not for inference.
pip uninstall -y sympy mpmath; \
elif [ "$BACKEND" = "pytorch" ]; then \
grep -vE "^(tensorflow|keras|mtcnn)==" /app/requirements_local.txt > /app/requirements_local_notf.txt && \
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org -r /app/requirements_local_notf.txt torch==2.1.2 facenet-pytorch==2.5.3 --extra-index-url https://download.pytorch.org/whl/cpu; \
elif [ "$BACKEND" = "onnx" ]; then \
grep -vE "^(tensorflow|keras|mtcnn)==" /app/requirements_local.txt > /app/requirements_local_notf.txt && \
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org -r /app/requirements_local_notf.txt && \
# onnxruntime depends on sympy for its symbolic shape inference tools only, not for inference.
pip uninstall -y sympy mpmath; \
else \
echo "Unsupported BACKEND=$BACKEND. It must be tensorflow, pytorch or onnx." && exit 1; \
fi
ENV DEEPFACE_BACKEND_ENGINE=$BACKEND
# 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 . --no-deps
# -----------------------------------
# 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
# -----------------------------------
# if you plan to serve deepface over grpc, then activate these lines to generate grpc stubs
# also activate grpc dependencies from requirements_local
# COPY ./Makefile /app/Makefile
# RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org grpcio==1.62.3 grpcio-tools==1.62.3
# RUN make grpc
# -----------------------------------
# environment variables
ENV PYTHONUNBUFFERED=1
# -----------------------------------
# run the app (re-configure port if necessary)
WORKDIR /app/deepface/api/src
EXPOSE 5000
# activate this line if you plan to serve deepface over grpc
# EXPOSE 50051
# CMD ["gunicorn", "--workers=1", "--timeout=3600", "--bind=0.0.0.0:5000", "app:create_app()"]
ENTRYPOINT [ "sh", "entrypoint.sh" ]