2015-11-01 20:52:46 +08:00
|
|
|
# Setup
|
|
|
|
The following instructions are for Linux and OSX only.
|
|
|
|
Please contribute modifications and build instructions if you
|
|
|
|
are interested in running this on other operating systems.
|
|
|
|
|
2015-11-24 04:35:27 +08:00
|
|
|
+ We strongly recommend using the [Docker](https://www.docker.com/)
|
|
|
|
container unless you are experienced with building
|
|
|
|
Linux software from source.
|
|
|
|
+ In OSX, you may have to change the hashbangs
|
|
|
|
from `python2` to `python`.
|
|
|
|
+ OpenFace has been tested in Ubuntu 14.04 and OSX 10.10
|
|
|
|
and may not work well on other distributions.
|
|
|
|
Please let us know of any challenges you had to overcome
|
|
|
|
getting OpenFace to work on other distributions.
|
2015-11-01 20:52:46 +08:00
|
|
|
|
2015-11-05 05:05:33 +08:00
|
|
|
## Warning for architectures other than 64-bit x86
|
|
|
|
See [#42](https://github.com/cmusatyalab/openface/issues/42).
|
|
|
|
|
2015-11-01 20:52:46 +08:00
|
|
|
## Check out git submodules
|
|
|
|
Clone with `--recursive` or run `git submodule init && git submodule update`
|
|
|
|
after checking out.
|
|
|
|
|
|
|
|
## With Docker
|
2015-12-24 04:41:23 +08:00
|
|
|
This repo can be used as a container with
|
|
|
|
[Docker](https://www.docker.com/) for CPU mode.
|
2015-11-01 20:52:46 +08:00
|
|
|
Depending on your Docker configuration, you may need to
|
|
|
|
run the docker commands as root.
|
|
|
|
|
2015-12-24 04:41:23 +08:00
|
|
|
### Automated Docker Build
|
|
|
|
The quickest way to getting started is to use our pre-built
|
|
|
|
automated Docker build, which is available from
|
|
|
|
[bamos/openface](https://hub.docker.com/r/bamos/openface/).
|
|
|
|
This does not require or use a locally checked out copy of OpenFace.
|
|
|
|
To use on your images, share a directory between your
|
|
|
|
host and the Docker container.
|
|
|
|
|
|
|
|
```
|
|
|
|
docker pull bamos/openface
|
|
|
|
docker run -p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash
|
|
|
|
cd /root/src/openface
|
|
|
|
./demos/compare.py images/examples/{lennon*,clapton*}
|
2016-01-17 13:58:27 +08:00
|
|
|
./demos/classifier.py infer models/openface/celeb-classifier.nn4.small2.v1.pkl ./images/examples/carell.jpg
|
2015-12-24 04:41:23 +08:00
|
|
|
./demos/web/start-servers.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Building a Docker Container
|
|
|
|
This builds a Docker container from a locally checked out copy of OpenFace,
|
|
|
|
which will take about 2 hours on a modern machine.
|
|
|
|
Be sure you have checked out the git submodules.
|
|
|
|
Run the following commands from the `openface` directory.
|
2015-11-01 20:52:46 +08:00
|
|
|
|
|
|
|
```
|
2015-12-23 12:13:30 +08:00
|
|
|
docker build -t openface .
|
2015-12-23 09:58:06 +08:00
|
|
|
docker run -p 9000:9000 -p 8000:8000 -t -i openface /bin/bash
|
|
|
|
cd /root/src/openface
|
2016-01-17 13:58:27 +08:00
|
|
|
./run-tests.sh
|
2015-11-01 20:52:46 +08:00
|
|
|
./demos/compare.py images/examples/{lennon*,clapton*}
|
2016-01-17 13:58:27 +08:00
|
|
|
./demos/classifier.py infer models/openface/celeb-classifier.nn4.small2.v1.pkl ./images/examples/carell.jpg
|
2015-12-23 13:44:37 +08:00
|
|
|
./demos/web/start-servers.sh
|
2015-11-01 20:52:46 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### Docker in OSX
|
|
|
|
In OSX, follow the
|
|
|
|
[Docker Mac OSX Installation Guide](https://docs.docker.com/installation/mac/)
|
|
|
|
and start a docker machine and connect your shell to it
|
|
|
|
before trying to build the container.
|
|
|
|
In the simplest case, this can be done with:
|
|
|
|
|
|
|
|
```
|
2015-12-04 02:40:35 +08:00
|
|
|
docker-machine create --driver virtualbox --virtualbox-memory 4096 default
|
2015-11-01 20:52:46 +08:00
|
|
|
eval $(docker-machine env default)
|
|
|
|
```
|
|
|
|
|
2015-12-04 02:40:35 +08:00
|
|
|
#### Docker memory issues in OSX
|
|
|
|
|
|
|
|
Some users have reported the following silent Torch/Lua failure
|
|
|
|
when running `batch-represent` caused by an out of memory issue.
|
|
|
|
|
|
|
|
```
|
|
|
|
/root/torch/install/bin/luajit: /openface/batch-represent/dataset.lua:191: attempt to perform arithmetic on a nil value
|
|
|
|
```
|
|
|
|
|
|
|
|
If you're experiencing this, make sure you have created a Docker machine
|
|
|
|
with at least 4GB of memory with `--virtualbox-memory 4096`.
|
|
|
|
|
2015-11-01 20:52:46 +08:00
|
|
|
## By hand
|
|
|
|
Be sure you have checked out the submodules and downloaded the models as
|
|
|
|
described above.
|
2015-11-05 21:58:28 +08:00
|
|
|
See the
|
2015-12-27 06:11:44 +08:00
|
|
|
[Dockerfile](https://github.com/cmusatyalab/openface/blob/master/Dockerfile)
|
2015-11-05 21:58:28 +08:00
|
|
|
as a reference.
|
2015-11-01 20:52:46 +08:00
|
|
|
|
|
|
|
This project uses `python2` because of the `opencv`
|
|
|
|
and `dlib` dependencies.
|
|
|
|
Install the packages the Dockerfile uses with your package manager.
|
|
|
|
With `pip2`, install `numpy`, `pandas`, `scipy`, `scikit-learn`, and `scikit-image`.
|
|
|
|
|
|
|
|
Next, manually install the following.
|
|
|
|
|
|
|
|
### OpenCV
|
|
|
|
Download [OpenCV 2.4.11](https://github.com/Itseez/opencv/archive/2.4.11.zip)
|
|
|
|
and follow their
|
|
|
|
[build instructions](http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html).
|
|
|
|
|
|
|
|
### dlib
|
2015-12-23 09:58:06 +08:00
|
|
|
dlib can be installed from [pypi](https://pypi.python.org/pypi/dlib)
|
|
|
|
or built manually and depends on boost libraries.
|
|
|
|
Building dlib manually with
|
|
|
|
[AVX support](http://dlib.net/face_landmark_detection_ex.cpp.html)
|
|
|
|
provides higher performance.
|
2015-11-01 20:52:46 +08:00
|
|
|
|
2015-12-23 09:58:06 +08:00
|
|
|
To build manually, download
|
2015-11-01 20:52:46 +08:00
|
|
|
[dlib v18.16](https://github.com/davisking/dlib/releases/download/v18.16/dlib-18.16.tar.bz2),
|
2015-12-23 09:58:06 +08:00
|
|
|
then run the following commands.
|
|
|
|
For the final command, make sure the directory is in your default
|
|
|
|
Python path, which can be found with `sys.path` in a Python interpreter.
|
|
|
|
In OSX, use `site-packages` instead of `dist-packages`.
|
2015-11-01 20:52:46 +08:00
|
|
|
|
|
|
|
```
|
|
|
|
mkdir -p ~/src
|
|
|
|
cd ~/src
|
|
|
|
tar xf dlib-18.16.tar.bz2
|
|
|
|
cd dlib-18.16/python_examples
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ../../tools/python
|
|
|
|
cmake --build . --config Release
|
2015-12-23 09:58:06 +08:00
|
|
|
sudo cp dlib.so /usr/local/lib/python2.7/dist-packages
|
2015-11-01 20:52:46 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
At this point, you should be able to start your `python2`
|
|
|
|
interpreter and successfully run `import cv2; import dlib`.
|
|
|
|
|
|
|
|
In OSX, you may get a `Fatal Python error: PyThreadState_Get: no current thread`.
|
|
|
|
You may be able to resolve by rebuilding `python` and `boost-python`
|
|
|
|
as reported in [#21](https://github.com/cmusatyalab/openface/issues/21),
|
|
|
|
but please file a new issue with us or [dlib](https://github.com/davisking/dlib)
|
|
|
|
if you are unable to resolve this.
|
|
|
|
|
|
|
|
### Torch
|
|
|
|
Install [Torch](http://torch.ch) from the instructions on their website
|
2015-12-09 07:31:11 +08:00
|
|
|
and install the dependencies with `luarocks install $NAME`,
|
|
|
|
where `$NAME` is as listed below.
|
|
|
|
|
|
|
|
+ [dpnn](https://github.com/nicholas-leonard/dpnn)
|
|
|
|
+ [nn](https://github.com/torch/nn)
|
|
|
|
+ [optim](https://github.com/torch/optim)
|
|
|
|
+ [csvigo](https://github.com/clementfarabet/lua---csv)
|
2015-12-17 22:09:41 +08:00
|
|
|
+ [cunn](https://github.com/torch/cunn) (only with CUDA)
|
2015-12-09 07:31:11 +08:00
|
|
|
+ [fblualib](https://github.com/facebook/fblualib)
|
|
|
|
(only for [training a DNN](http://cmusatyalab.github.io/openface/training-new-models/))
|
2016-01-17 05:32:16 +08:00
|
|
|
+ [torchx](https://github.com/nicholas-leonard/torchx)
|
|
|
|
(only for [training a DNN](http://cmusatyalab.github.io/openface/training-new-models/))
|
2015-11-01 20:52:46 +08:00
|
|
|
|
|
|
|
At this point, the command-line program `th` should
|
|
|
|
be available in your shell.
|
2015-12-23 09:58:06 +08:00
|
|
|
|
|
|
|
### OpenFace
|
2016-01-14 05:15:53 +08:00
|
|
|
In OSX, install `findutils` and `coreutils` with Brew or MacPorts for
|
|
|
|
the prefixed GNU variants `gfind` and `gwc`.
|
|
|
|
These are required for the commands to be compatible with
|
|
|
|
the Linux defaults of these commands.
|
|
|
|
|
|
|
|
From the root OpenFace directory,
|
|
|
|
install the Python dependencies with
|
|
|
|
`sudo python2 setup.py install`.
|
2015-12-23 09:58:06 +08:00
|
|
|
|
|
|
|
Run [models/get-models.sh](https://github.com/cmusatyalab/openface/blob/master/models/get-models.sh)
|
|
|
|
to download pre-trained OpenFace
|
|
|
|
models on the combined CASIA-WebFace and FaceScrub database.
|
|
|
|
This also downloads dlib's pre-trained model for face landmark detection.
|
2016-01-14 05:15:53 +08:00
|
|
|
This will incur about 200MB of network traffic.
|