Create an environment (Docker image) that can run OpenFace with Python3 + Ubuntu16.04, and try running the sample code of OpenFace face recognition (comparison of the distance between two faces) on the container.
Created by Brandon Amos of Carnegie Mellon University. It is open source specialized for face recognition using deep neural networks. It is a Python and Torch implementation and is based on CVPR 2015. Below is a summary of the algorithm and release notes. https://cmusatyalab.github.io/openface/
OpenFace algorithm, (1) Face detection with pre-trained model with dlib or OpenCV (2) Convert so that the positions of the eyes and lower lip in the face are the same using the affine transformation of OpenCV and the real-time pose estimation of dlib. (3) Represent (or embed) faces on a 128-dimensional unit hypersphere using a deep neural network, and perform face recognition by clustering, similarity detection, and classification tasks. ... apparently ...
-Docker is installed on the PC
Create the following Dockerfile in the working directory.
I created it for the time being, so there may be extra commands.
Dockerfile
FROM ubuntu:16.04
#apt package update
#Install the required apt packages
RUN apt-get update && apt-get upgrade -y && apt-get install -y wget sudo python-setuptools python-pip liblapack-dev libatlas-base-dev gfortran g++ build-essential libgtk2.0-dev libjpeg-dev libtiff5-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk ant libvtk5-qt4-dev unzip cmake git python-dev python-numpy libboost-dev libboost-python-dev libboost-system-dev
#Install the required pip packages
RUN sudo pip install -U pip && sudo pip install numpy==1.12.0 scipy matplotlib cython scikit-image dlib pandas txaio
#Install Torch
WORKDIR /root
RUN git clone https://github.com/torch/distro.git ~/torch --recursive
WORKDIR /root/torch
RUN sudo dpkg --configure -a
RUN bash install-deps
RUN ./install.sh -y
RUN . /root/.bashrc
#PATH of th command
RUN export PATH=/root/torch/bin:$PATH;
RUN export LD_LIBRARY_PATH=/root/torch/lib:$LD_LIBRARY_PATH;
#Install LUA package for Torch
#lua to build luarocks**Install in advance as you will need.
RUN sudo apt-get install lua5.3
RUN sudo apt-get install -y lua5.3-dev
#Install luarocks
RUN mkdir luarocks
WORKDIR /root/torch/luarocks
RUN wget https://luarocks.org/releases/luarocks-3.3.1.tar.gz
RUN tar -xf luarocks-3.3.1.tar.gz
WORKDIR /root/torch/luarocks/luarocks-3.3.1
RUN ./configure
RUN make
RUN make install
#LUA package installation
RUN for NAME in dpnn nn optim optnet csvigo cutorch cunn fblualib torchx tds image nngraph; do sudo /root/torch/install/bin/luarocks install $NAME; done
#Install OpenFace
RUN git clone https://github.com/cmusatyalab/openface ~/openface --recursive
WORKDIR /root/openface
RUN sudo python setup.py install
RUN sudo python3 setup.py install
#Install additional required items
RUN ./models/get-models.sh
RUN ./demos/web/install-deps.sh
RUN sudo pip install -r demos/web/requirements.txt
#Install what you need to run OpenFace on python3
WORKDIR /root
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN sudo python3 get-pip.py && python3 -m pip install -U pip
RUN sudo apt-get install -y python3-dev
# OpenCV,dlib installation
RUN python3 -m pip install opencv_python dlib
terminal
usermac:~ user$ ls {Working directory}
Dockerfile #Created Dockerfile
terminal
docker build -t openface_ubuntu16_python3:1.0 {Relative or absolute path to the working directory where Docker files are located}
terminal
docker run -it -v {Absolute path of working directory}:/home/ openface_ubuntu16_python3:1.0 /bin/bash .
The working directory of the host and the home directory of the container are shared (volume).
terminal
usermac:work user$ pwd
/Users/{username}/openface_sample/work
Check the OpenFace source and demo code in ~ / openface
.
container
root@bb9464b46285:~# ls openface/
CONTRIBUTING.md LICENSE api-docs build data docs images models openface run-tests.sh tests util
Dockerfile README.md batch-represent cloc.sh demos evaluation mkdocs.yml opencv-dlib-torch.Dockerfile requirements.txt setup.py training
This time, run the demo code compare.py to determine if the faces in the two photos are the same person.
container
root@bb9464b46285:~# python3 openface/demos/compare.py openface/images/examples/lennon-1.jpg openface/images/examples/lennon-2.jpg
Comparing images/examples/lennon-1.jpg with images/examples/lennon-2.jpg.
+ Squared l2 distance between representations: 0.782 #Execution result
I want to compare ʻopenface / images / examples / lennon-1.jpg and ʻopenface / images / examples / lennon-2.jpg
specified after python3 openface / demos / compare.py
2 Specify the number of images.
This time, I used the sample image placed under openface. If the face cannot be detected from the specified image, an error will occur.
The distance between the two faces compared by 0.782
. The closer it is to 0
, the more likely it is that they are the same person.
It seems that the standard value needs to be judged by verifying it with the photos actually used.
Recommended Posts