Installing OpenFace: an open source facial behavior analysis toolkit (Ubuntu 16.04)

EDIT: 06/15/2017 Additional compile time troubleshooting tips added.

Installation System: Ubuntu 16.04

1. Installing dependencies:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install llvm
sudo gedit /etc/apt/sources.list
change
deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
to
deb http://us.archive.ubuntu.com/ubuntu/ xenial main universe
sudo apt-get update
sudo apt-get install clang-3.7 libc++-dev libc++abi-dev
sudo apt-get install cmake
sudo apt-get install libopenblas-dev liblapack-dev
sudo apt-get install git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev checkinstall
wget https://github.com/Itseez/opencv/archive/3.1.0.zip
sudo unzip 3.1.0.zip
cd opencv-3.1.0
mkdir build
cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_SHARED_LIBS=OFF ..
make -j4
sudo make install
sudo apt-get install libboost-all-dev

2. Installing OpenFace

git clone https://github.com/TadasBaltrusaitis/OpenFace.git
cd OpenFace/
mkdir build

cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE ..
make

Ref: https://github.com/TadasBaltrusaitis/OpenFace/wiki/Unix-Installation

3. Using from MATLAB  (Error Resolution: ibstdc++.so.6: version `CXXABI_1.3.8′ not found)

To solve this issue, I found setting the LD_LIBARARY_PATH from the script works for me. Just add the following at the beginning of the script (change the libstdc++.so.6 path according to your system):

setenv('LD_LIBRARY_PATH', '/usr/lib/x86_64-linux-gnu/libstdc++.so.6');

Sample script for running FaceLandmarkImg

from subprocess import call


# FaceLandmarkImg
#
# Single image analysis
#
# -f  the image file being input, can have multiple -f flags
# -of  location of output file for landmark points, gaze and action units
# -op  location of output file for 3D landmark points and head pose
# -gaze indicate that gaze estimation should be performed
# -oi  location of output image with landmarks
# -root  the root directory so -f, -of, -op, and -oi can be specified relative to it
# -inroot  the input root directory so -f can be specified relative to it
# -outroot  the root directory so -of, -op, and -oi can be specified relative to it
#
# Batch image analysis
#
# -fdir  - runs landmark detection on all images (.jpg and .png) in a directory, if the directory contains
# .txt files (image_name.txt) with bounding box (min_x min_y max_x max_y), it will use those for initialisation
# -ofdir  directory where detected landmarks, gaze, and action units should be written
# -oidir  directory where images with detected landmarks should be stored
# -opdir  directory where pose files are output (3D landmarks in images together with head pose and gaze)

exe = "../build/bin/FaceLandmarkImg"

# f_param = './OpenFace/image_sequence/001.jpg'
# of_param = './OpenFace/python/img_output/001.txt'
# op_param = './OpenFace/python/img_output/001_3d.txt'
# oi_param = './OpenFace/python/img_output/001.jpg'
# call([exe, "-f", f_param, "-of", of_param, "-op", op_param, "-oi", oi_param])

fdir_param = './OpenFace/image_sequence/'
ofdir_param = './OpenFace/python/imgseq_output'
oidir_param = ofdir_param
opdir_param = ofdir_param

call([exe, "-fdir", fdir_param, "-ofdir", ofdir_param, "-oidir", oidir_param, "-opdir", opdir_param, "-wild"])

 
UDPATE: 06/15/17

The following problem are faced when trying to install OpenFace using their install.sh installation script.

COMPILETIME ERROR 1: OpenCV3.1.0 Installation issue: cudalegacy not compile

This problem you’ll face if are trying to compile with CUDA-8.0:

try this: in graphcuts.cpp (where your error is thrown) change this:

#include "precomp.hpp"

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
to this:

#include "precomp.hpp"

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
because graphcuts is not supported directly with CUDA8 anymore.

COMPILE TIME ERROR 2: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_glyph_cache_remove'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_composite_glyphs_no_mask'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_glyph_get_mask_format'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_glyph_cache_insert'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_glyph_cache_freeze'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_glyph_cache_thaw'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_glyph_cache_lookup'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_composite_glyphs'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcairo.so: undefined reference to `pixman_glyph_cache_create

Solution: 1) Install libpixman-1-dev
sudo apt-get install libpixman-1-dev
2) Modify link.txt files to add "-lpixman-1" switch. Path to link.txt -
build/exe/FaceLandmarkImg/CMakeFiles/FaceLandmarkImg.dir/link.txt
build/exe/FaceLandmarkVid/CMakeFiles/FaceLandmarkVid.dir/link.txt
build/exe/FaceLandmarkVidMulti/CMakeFiles/FaceLandmarkVidMulti.dir/link.txt
build/exe/FeatureExtraction/CMakeFiles/FeatureExtraction.dir/link.txt

Advertisements

Installing Nvidia DIGITS on Ubuntu 16.04.1

(I am assuming caffe and pycaffe are already successfully installed. If not, check my previous post on that.)

1. Install dependencies

sudo apt-get install --no-install-recommends git graphviz gunicorn python-dev python-flask python-flaskext.wtf python-gevent python-h5py python-numpy python-pil python-protobuf python-scipy

2. Download and install source

DIGITS_HOME=~/digits
git clone https://github.com/NVIDIA/DIGITS.git $DIGITS_HOME

3. Install python packages [Upgrade pip if needed]

sudo pip install -r $DIGITS_HOME/requirements.txt

4. Set an environment variable in ~/.bashrc so DIGITS knows where Caffe is installed:

export CAFFE_HOME=${HOME}/caffe

Remeber DIGITS will look for caffe binaries in ${HOME}/caffe/build/tools/ directory, so make sure the binaries are installed in that manner.

5. Start DIGITS server

 ./digits-server 

6. The default location of the web app is

 http://localhost:34448/

Installing Caffe with Cuda 7.5 on Ubuntu 16.04.1 (Nvidia GeForce GTX 960M GPU)

There are three main steps:

Step 1: Installing the Nvidia graphics driver

Step 2: Installing Cuda 7.5

Step 3: Installing Caffe, pycaffe

Step 1: Installing the Nvidia graphics driver

Ref: http://askubuntu.com/questions/658040/ubuntu-14-04-nvidia-drivers-for-geforce-gtx-960m


sudo apt-get purge nvidia*
sudo apt-get purge bumblebee* primus
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-352 nvidia-prime
sudo add-apt-repository -r ppa:bumblebee/stable

Step 2: Installing Cuda 7.5

Ref: http://askubuntu.com/questions/799184/how-can-i-install-cuda-on-ubuntu-16-04

1. Download cuda_7.5.18_linux.run from https://developer.nvidia.com/cuda-downloads

2.

md5sum cuda_7.5.18_linux.run
sudo apt-get purge nvidia-cuda*
sudo sh cuda_7.5.18_linux.run --override
sudo reboot

Step 3: Installing Caffe, pycaffe
Ref: https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide

1. Enter the following commands


sudo apt-get update

sudo apt-get upgrade

sudo apt-get install -y build-essential cmake git pkg-config

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler

sudo apt-get install -y libatlas-base-dev

sudo apt-get install -y --no-install-recommends libboost-all-dev

sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev

# (Python general)
sudo apt-get install -y python-pip

# (Python 2.7 development files)
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy

# (OpenCV 2.4)
sudo apt-get install -y libopencv-dev

2. clone caffe repository

 git clone https://github.com/BVLC/caffe.git 

3. enter caffe folder and copy the Makefile.config

 cp Makefile.config.example Makefile.config 

4. Edit Makefile.config as follows


PYTHON_INCLUDE := /usr/include/python2.7 /usr/lib/python2.7/dist-packages/numpy/core/include

WITH_PYTHON_LAYER := 1

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

5. Apply the following commands (for Ubuntu 16.04)

find . -type f -exec sed -i -e 's^"hdf5.h"^"hdf5/serial/hdf5.h"^g' -e 's^"hdf5_hl.h"^"hdf5/serial/hdf5_hl.h"^g' '{}' \;

cd /usr/lib/x86_64-linux-gnu

sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so

sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so

6. Installing required python packages

cd python

for req in $(cat requirements.txt); do pip install $req; done

7. Go back to caffe installation folder (~/caffe e.g.), and run the installation commands:

make all

make test

make runtest

make pycaffe

8. In order to make the Python work with Caffe, open the file ~/.bashrc for editing in your favorite text editor. There, add the following line at the end of file:

export PYTHONPATH=/path/to/caffe-master/python:$PYTHONPATH

9. Your binaries will reside in .build_release folder

~/caffe/.build_release/tools/ 

ERROR Resolution: “error — unsupported GNU version! gcc versions later than 5.3 are not supported!”

comment the #error line in file /usr/local/cuda/include/host_config.h

#if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 3)

//#error — unsupported GNU version! gcc versions later than 5.3 are not supported!

#endif /* __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 1) */

ERROR Resolution: “/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
return (char *) memcpy (__dest, __src, __n) + __n;
^
Makefile:588: recipe for target ‘.build_release/cuda/src/caffe/util/im2col.o’ failed
make: *** [.build_release/cuda/src/caffe/util/im2col.o] Error 1

If you are compiling with make then edit Makefile and replace the line
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
with
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

Compiling congealReal: Unsupervised joint alignment of complex images

The c++ code provided for the project ‘Unsupervised joint alignment of complex images’ at https://bitbucket.org/gbhuang/congealreal is very useful application for unsupervised image alignment. But the Makefile is now outdated, but we can fix it by modifying it as following,


IFLAGS = `pkg-config --cflags opencv` -O3
LFLAGS = `pkg-config opencv --libs`

all: congealReal funnelReal

clean:
rm congealReal funnelReal

congealReal: congealReal.cpp
g++ $(IFLAGS) -o congealReal congealReal.cpp $(LFLAGS)

funnelReal: funnelReal.cpp
g++ $(IFLAGS) -o funnelReal funnelReal.cpp $(LFLAGS)