diff --git a/README.md b/README.md index df0e0f17d8e31911d333b3bbbc61627304b51c7e..23ac8647d4435f915f094ff52c928f2d0368e302 100644 --- a/README.md +++ b/README.md @@ -394,6 +394,8 @@ to any service that supports Docker images. You can try the Docker image locally by running: `docker-compose up --build` +There are also [several prebuilt Docker images.](docker/README.md) + Linux users with a GPU (drivers >= 384.81) and [Nvidia-Docker](https://github.com/NVIDIA/nvidia-docker) installed can run the example on the GPU: Open the [docker-compose.yml](docker-compose.yml) file and uncomment the `dockerfile: Dockerfile.gpu` and `runtime: nvidia` lines. ## Having problems? diff --git a/docker/Dockerfile-python-example b/docker/Dockerfile-python-example new file mode 100644 index 0000000000000000000000000000000000000000..159fab37f1526f89dd116e9f6b85b62a6c6a5cc0 --- /dev/null +++ b/docker/Dockerfile-python-example @@ -0,0 +1,17 @@ +FROM animcogn/face_recognition:cpu + +# The rest of this file just runs an example script. + +# If you wanted to use this Dockerfile to run your own app instead, maybe you would do this: +# COPY . /root/your_app_or_whatever +# RUN cd /root/your_app_or_whatever && \ +# pip3 install -r requirements.txt +# RUN whatever_command_you_run_to_start_your_app + +COPY . /root/face_recognition +RUN cd /root/face_recognition && \ + pip3 install -r requirements.txt && \ + python3 setup.py install + +CMD cd /root/face_recognition/examples && \ + python3 recognize_faces_in_pictures.py diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6feffe1e462604d951a3f7804b0b71e20b461895 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,56 @@ +# Docker Builds + +If you've never used Docker before, check out the [getting started guide.](https://docs.docker.com/get-started/) + +Up-to-date prebuilt images can be found [on Docker hub.](https://hub.docker.com/repository/docker/animcogn/face_recognition) + +## CPU Images + +- [`cpu-latest`, `cpu`, `cpu-0.1`, `latest`](cpu/Dockerfile) +- [`cpu-jupyter-kubeflow-latest`, `cpu-jupyter-kubeflow`, `cpu-jupyter-kubeflow-0.1`](cpu-jupyter-kubeflow/Dockerfile) + +### GPU Images +- [`gpu-latest`, `gpu`, `gpu-0.1`](gpu/Dockerfile) +- [`gpu-jupyter-kubeflow-latest`, `gpu-jupyter-kubeflow`, `gpu-jupyter-kubeflow-0.1`](gpu-jupyter-kubeflow/Dockerfile) + +The CPU images should run out of the box without any driver prerequisites. + +## GPU Images + +### Prerequisites + +To use the GPU images, you need to have: +- [The Nvidia drivers](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#nvidia-drivers) +- [The Nvidia-docker container runtime](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit) +- [Docker configured to use the Nvidia container runtime](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html#daemon-configuration-file) + +Once you have those installed, you should be ready to start running the GPU instances. + +### Testing GPUs + +To make sure your GPU instance is setup correctly, run the following in a container: + +```python3 +import dlib +print(dlib.cuda.get_num_devices()) +``` + +## Jupyter Images + +The Jupyter images are built to be deployed on [Kubeflow](https://www.kubeflow.org/). However, if you just want to run a normal Jupyter instance, they're a great template to build your own. + +## Example Dockerfile + +Here's an example Dockerfile using the prebuilt images: + +```Dockerfile +FROM animcogn/face_recognition:gpu + +COPY requirements.txt requirements.txt + +RUN pip3 install -r ./requirements.txt + +COPY my_app /my_app + +CMD [ "python3", "/my_app/my_app.py" ] +``` diff --git a/docker/cpu-jupyter-kubeflow/Dockerfile b/docker/cpu-jupyter-kubeflow/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..9979c548a1411f3f90b9652b79db0d0ddda628f1 --- /dev/null +++ b/docker/cpu-jupyter-kubeflow/Dockerfile @@ -0,0 +1,15 @@ +FROM animcogn/face_recognition:cpu + +RUN useradd -ms /bin/bash jovyan && \ + chown -R jovyan:jovyan /opt/venv && \ + echo 'PATH="/opt/venv/bin:$PATH"' >> /home/jovyan/.bashrc + +USER jovyan + +ENV PATH="/opt/venv/bin:$PATH" + +RUN pip3 install jupyterlab + +ENV NB_PREFIX / + +CMD ["sh", "-c", "jupyter lab --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"] diff --git a/docker/cpu/Dockerfile b/docker/cpu/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..08a40e25c3c9bb72698899f7bf0a1978e4c309b6 --- /dev/null +++ b/docker/cpu/Dockerfile @@ -0,0 +1,74 @@ +# Builder Image +FROM python:3.8-slim-buster AS compile + +# Install Dependencies +RUN apt-get -y update && apt-get install -y --fix-missing \ + build-essential \ + cmake \ + gfortran \ + git \ + wget \ + curl \ + graphicsmagick \ + libgraphicsmagick1-dev \ + libatlas-base-dev \ + libavcodec-dev \ + libavformat-dev \ + libgtk2.0-dev \ + libjpeg-dev \ + liblapack-dev \ + libswscale-dev \ + pkg-config \ + python3-dev \ + python3-numpy \ + software-properties-common \ + zip \ + && apt-get clean && rm -rf /tmp/* /var/tmp/* + +# Virtual Environment +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# Install Dlib +ENV CFLAGS=-static +RUN pip3 install --upgrade pip && \ + git clone -b 'v19.21' --single-branch https://github.com/davisking/dlib.git && \ + cd dlib/ && \ + python3 setup.py install --set BUILD_SHARED_LIBS=OFF + +RUN pip3 install face_recognition + + +# Runtime Image +FROM python:3.8-slim-buster + +COPY --from=compile /opt/venv /opt/venv +COPY --from=compile \ + # Sources + /lib/x86_64-linux-gnu/libpthread.so.0 \ + /lib/x86_64-linux-gnu/libz.so.1 \ + /lib/x86_64-linux-gnu/libm.so.6 \ + /lib/x86_64-linux-gnu/libgcc_s.so.1 \ + /lib/x86_64-linux-gnu/libc.so.6 \ + /lib/x86_64-linux-gnu/libdl.so.2 \ + /lib/x86_64-linux-gnu/librt.so.1 \ + # Destination + /lib/x86_64-linux-gnu/ + +COPY --from=compile \ + # Sources + /usr/lib/x86_64-linux-gnu/libX11.so.6 \ + /usr/lib/x86_64-linux-gnu/libXext.so.6 \ + /usr/lib/x86_64-linux-gnu/libpng16.so.16 \ + /usr/lib/x86_64-linux-gnu/libjpeg.so.62 \ + /usr/lib/x86_64-linux-gnu/libstdc++.so.6 \ + /usr/lib/x86_64-linux-gnu/libxcb.so.1 \ + /usr/lib/x86_64-linux-gnu/libXau.so.6 \ + /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 \ + /usr/lib/x86_64-linux-gnu/libbsd.so.0 \ + # Destination + /usr/lib/x86_64-linux-gnu/ + +# Add our packages +ENV PATH="/opt/venv/bin:$PATH" diff --git a/docker/gpu-jupyter-kubeflow/Dockerfile b/docker/gpu-jupyter-kubeflow/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..df0aa8ac88f95aacdd8c6c54ac99867f027a23d3 --- /dev/null +++ b/docker/gpu-jupyter-kubeflow/Dockerfile @@ -0,0 +1,15 @@ +FROM animcogn/face_recognition:gpu + +RUN useradd -ms /bin/bash jovyan && \ + chown -R jovyan:jovyan /opt/venv && \ + echo 'PATH="/opt/venv/bin:$PATH"' >> /home/jovyan/.bashrc + +USER jovyan + +ENV PATH="/opt/venv/bin:$PATH" + +RUN pip3 install jupyterlab + +ENV NB_PREFIX / + +CMD ["sh", "-c", "jupyter lab --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"] diff --git a/docker/gpu/Dockerfile b/docker/gpu/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..8ece32dec82126c0c6590991d4da75658ae26f9b --- /dev/null +++ b/docker/gpu/Dockerfile @@ -0,0 +1,97 @@ +FROM nvidia/cuda:11.2.0-cudnn8-devel AS compile + +# Install dependencies +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update -y && apt-get install -y \ + git \ + cmake \ + libsm6 \ + libxext6 \ + libxrender-dev \ + python3 \ + python3-pip \ + python3-venv \ + python3-dev \ + python3-numpy \ + gcc \ + build-essential \ + gfortran \ + wget \ + curl \ + graphicsmagick \ + libgraphicsmagick1-dev \ + libatlas-base-dev \ + libavcodec-dev \ + libavformat-dev \ + libgtk2.0-dev \ + libjpeg-dev \ + liblapack-dev \ + libswscale-dev \ + pkg-config \ + software-properties-common \ + zip \ + && apt-get clean && rm -rf /tmp/* /var/tmp/* + + +# Virtual Environment +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# Scikit learn +RUN pip3 install --upgrade pip && \ + pip3 install scikit-build + +# Install dlib +ENV CFLAGS=-static +RUN git clone -b 'v19.21' --single-branch https://github.com/davisking/dlib.git dlib/ && \ + mkdir -p /dlib/build && \ + cmake -H/dlib -B/dlib/build -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 && \ + cmake --build /dlib/build && \ + cd /dlib && \ + python3 /dlib/setup.py install --set BUILD_SHARED_LIBS=OFF + +# Install face recognition +RUN pip3 install face_recognition + +# Runtime Image +FROM nvidia/cuda:11.2.0-cudnn8-runtime + +# Install requirements +RUN apt-get update && apt-get install -y \ + python3 \ + python3-distutils + +# Copy in libs +COPY --from=compile /opt/venv /opt/venv +COPY --from=compile \ + # Sources + /lib/x86_64-linux-gnu/libpthread.so.0 \ + /lib/x86_64-linux-gnu/libdl.so.2 \ + /lib/x86_64-linux-gnu/librt.so.1 \ + /lib/x86_64-linux-gnu/libX11.so.6 \ + /lib/x86_64-linux-gnu/libpng16.so.16 \ + /lib/x86_64-linux-gnu/libjpeg.so.8 \ + /lib/x86_64-linux-gnu/libcudnn.so.8 \ + /lib/x86_64-linux-gnu/libstdc++.so.6 \ + /lib/x86_64-linux-gnu/libm.so.6 \ + /lib/x86_64-linux-gnu/libgcc_s.so.1 \ + /lib/x86_64-linux-gnu/libc.so.6 \ + /lib/x86_64-linux-gnu/libxcb.so.1 \ + /lib/x86_64-linux-gnu/libz.so.1 \ + /lib/x86_64-linux-gnu/libXau.so.6 \ + /lib/x86_64-linux-gnu/libXdmcp.so.6 \ + /lib/x86_64-linux-gnu/libbsd.so.0 \ + # Destination + /lib/x86_64-linux-gnu/ +COPY --from=compile \ + # Sources + /usr/local/cuda/lib64/libcublas.so.11 \ + /usr/local/cuda/lib64/libcurand.so.10 \ + /usr/local/cuda/lib64/libcusolver.so.11 \ + /usr/local/cuda/lib64/libcublasLt.so.11 \ + # Destination + /usr/local/cuda/lib64/ + +# Add our packages +ENV PATH="/opt/venv/bin:$PATH"