From ff867ec342b3b57c212958c26febab5f2fa0e8f6 Mon Sep 17 00:00:00 2001 From: Enric Moreu Date: Sun, 3 Mar 2019 17:39:58 +0000 Subject: [PATCH] Dockerfile.gpu alongside CPU based Dockerfile --- Dockerfile | 86 ++++++++++++++++++++++++++-------------------- Dockerfile.gpu | 40 +++++++++++++++++++++ README.md | 2 +- docker-compose.yml | 5 ++- 4 files changed, 93 insertions(+), 40 deletions(-) create mode 100644 Dockerfile.gpu diff --git a/Dockerfile b/Dockerfile index ee2bff9..3072e09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,50 @@ # This is a sample Dockerfile you can modify to deploy your own app based on face_recognition -# In order to run Docker in the GPU you will need to install nvidia-docker: https://github.com/NVIDIA/nvidia-docker -FROM nvidia/cuda:9.0-cudnn7-devel - -# Install face recognition dependencies - -RUN apt update -y; apt install -y \ -git \ -cmake \ -libsm6 \ -libxext6 \ -libxrender-dev \ -python3 \ -python3-pip - -RUN pip3 install scikit-build - -# Install compilers - -RUN apt install -y software-properties-common -RUN add-apt-repository ppa:ubuntu-toolchain-r/test -RUN apt update -y; apt install -y gcc-6 g++-6 - -RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50 -RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 50 - -#Install dlib - -RUN git clone https://github.com/davisking/dlib.git -RUN mkdir -p /dlib/build - -RUN cmake -H/dlib -B/dlib/build -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 -RUN cmake --build /dlib/build - -RUN cd /dlib; python3 /dlib/setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA - -# Install the face recognition package - -RUN pip3 install face_recognition +FROM python:3.6-slim-stretch + +RUN apt-get -y update +RUN apt-get install -y --fix-missing \ + build-essential \ + cmake \ + gfortran \ + git \ + wget \ + curl \ + graphicsmagick \ + libgraphicsmagick1-dev \ + libatlas-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/* + +RUN cd ~ && \ + mkdir -p dlib && \ + git clone -b 'v19.9' --single-branch https://github.com/davisking/dlib.git dlib/ && \ + cd dlib/ && \ + python3 setup.py install --yes USE_AVX_INSTRUCTIONS + + +# 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 \ No newline at end of file diff --git a/Dockerfile.gpu b/Dockerfile.gpu new file mode 100644 index 0000000..2702e63 --- /dev/null +++ b/Dockerfile.gpu @@ -0,0 +1,40 @@ +# This is a sample Dockerfile you can modify to deploy your own app based on face_recognition on the GPU +# In order to run Docker in the GPU you will need to install Nvidia-Docker: https://github.com/NVIDIA/nvidia-docker + +FROM nvidia/cuda:9.0-cudnn7-devel + +# Install face recognition dependencies + +RUN apt update -y; apt install -y \ +git \ +cmake \ +libsm6 \ +libxext6 \ +libxrender-dev \ +python3 \ +python3-pip + +RUN pip3 install scikit-build + +# Install compilers + +RUN apt install -y software-properties-common +RUN add-apt-repository ppa:ubuntu-toolchain-r/test +RUN apt update -y; apt install -y gcc-6 g++-6 + +RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50 +RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 50 + +#Install dlib + +RUN git clone https://github.com/davisking/dlib.git +RUN mkdir -p /dlib/build + +RUN cmake -H/dlib -B/dlib/build -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 +RUN cmake --build /dlib/build + +RUN cd /dlib; python3 /dlib/setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA + +# Install the face recognition package + +RUN pip3 install face_recognition diff --git a/README.md b/README.md index 7ee2167..4e7821e 100644 --- a/README.md +++ b/README.md @@ -371,7 +371,7 @@ to any service that supports Docker images. You can try the Docker image locally by running: `docker-compose up` -If you don't have nvidia-docker installed or a GPU, remove the last line in the [docker-compose.yml](docker-compose.yml) file (`runtime: nvidia`). +Linux users with a GPU 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-compose.yml b/docker-compose.yml index 6706bcd..c46125e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,10 @@ services: working_dir: /face_recognition/examples build: context: . + #Uncomment this line to run the example on the GPU (requires Nvidia-Docker) + # dockerfile: Dockerfile.gpu command: python3 -u find_faces_in_picture_cnn.py volumes: - ./:/face_recognition - runtime: nvidia #Comment this line if you don't have nvidia-docker installed (requires GPU) \ No newline at end of file + #Uncomment this line to run the example on the GPU (requires Nvidia-Docker) + # runtime: nvidia \ No newline at end of file -- GitLab