Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Last active May 12, 2022 11:22
Show Gist options
  • Save tashrifbillah/fe4e7a5db279a10a8a0a3dd43db9e59f to your computer and use it in GitHub Desktop.
Save tashrifbillah/fe4e7a5db279a10a8a0a3dd43db9e59f to your computer and use it in GitHub Desktop.
OpenFace installation on CentOS 7

The instruction at https://github.com/TadasBaltrusaitis/OpenFace/wiki/Unix-Installation is for Ubuntu. But following the idea, I have been able to install it on CentOS 7. I am documenting the changes here for future. A major contribution of mine is to complete the installation without sudo.


Table of Contents


GCC

OpenFace requires GCC>=8 so I installed 9.3.0:

# download and install
wget https://ftp.gnu.org/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
tar -xzf gcc-9.3.0
cd gcc-9.3.0
mkdir build && cd build
../configure --disable-multilib --prefix=~/gcc-9.3.0/gccbuild
make -j 4
make install

# update environment for auto discovery by future cmake
export LD_LIBRARY_PATH=~/gcc-9.3.0/gccbuild/lib64:$LD_LIBRARY_PATH
export PATH=~/gcc-9.3.0/gccbuild/bin/:$PATH

Boost

Although the wiki says Boost optional, my attempts were failing in the absence of a recent version. So, I had to install Boost 1.70.0. The following is inspired by this:

# download and install
wget https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.tar.gz
tar -xzf boost_1_70_0.tar.gz
cd boost_1_70_0
./bootstrap.sh --prefix=`pwd`/build
./b2 install

# update environment for auto discovery by future cmake
export LD_LIBRARY_PATH=~/boost_1_70_0/build/lib/:$LD_LIBRARY_PATH

Not only that, I also had to insert BOOST_ROOT here to facilitate its detection by cmake during OpenFace building:

find_package( Boost 1.70.0 COMPONENTS filesystem system)
set ( BOOST_ROOT "$HOME/boost_1_70_0/build/" CACHE PATH "Boost library path" )

Providing -DBOOST_ROOT=$HOME/boost_1_70_0/build/ from the command line to cmake did not work.

dlib

wget http://dlib.net/files/dlib-19.13.tar.bz2
tar xf dlib-19.13.tar.bz2
cd dlib-19.13 && mkdir build && cd build
cmake ..
cmake --build . --config Release
make install

FFmpeg

Inspired by this. Note that I had to remove the --disable-ffmpeg flag from that.

# download and install
git clone https://github.com/FFmpeg/FFmpeg.git
cd FFmpeg
git checkout n4.0.2
./configure --prefix=`pwd`/build \
--enable-avresample \
--enable-pic --disable-asm --disable-debug \
--disable-cuda --disable-cuvid
make install

# update environment for auto discovery by future cmake
export LD_LIBRARY_PATH=~/FFmpeg/build/lib/:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=~/FFmpeg/build/lib/pkgconfig:$PKG_CONFIG_PATH

OpenCV

wget https://github.com/opencv/opencv/archive/4.1.0.zip
unzip 4.1.0.zip
cd opencv-4.1.0

Miniconda3

I observed PYTHON3* variables in ccmake of OpenCV so installing a separate Miniconda3 for OpenCV. This installation and associated variables can probably be skipped.

# install miniconda3 inside opencv-4.1.0 so it remains separate from other miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.10.3-Linux-x86_64.sh
chmod a+x Miniconda3-py38_4.10.3-Linux-x86_64.sh
./Miniconda3-py38_4.10.3-Linux-x86_64.sh -b -p miniconda3

# source to facilitate auto detection of PYTHON3* variables although not sure how effective
source miniconda3/bin/activate

OpenCV

(Not for faint-hearted ones)

Note that I had to remove -DWITH_TBB=ON from OpenFace wiki probably because I did not do yum install tbb tbb-devel.

mkdir build && cd build

# keep it ccmake because you may have to update PYTHON3_LIBRARIES and PYTHON3_INCLUDE_DIRS
# in the event they are not auto detected
ccmake -DCMAKE_INSTALL_PREFIX=~/opencv-4.1.0/cvbuild \
-DCMAKE_CXX_COMPILER=~/gcc-9.3.0/gccbuild/bin/g++ -DCMAKE_C_COMPILER=~/gcc-9.3.0/gccbuild/bin/gcc \
-DPYTHON3_INCLUDE_DIR=/home/tb571/Downloads/opencv-4.1.0/miniconda3/include/ \
-DPYTHON3_LIBRARY=/home/tb571/Downloads/opencv-4.1.0/miniconda3/lib/ \
-DPYTHON3_NUMPY_INCLUDE_DIRS=/home/tb571/Downloads/opencv-4.1.0/miniconda3/lib/python3.*/site-packages/numpy \
-DPYTHON3_PACKAGES_PATH=/home/tb571/Downloads/opencv-4.1.0/miniconda3/lib/python3.*/site-packages \
-DBUILD_TIFF=ON -DWITH_V4L=ON -DFFMPEG=1 ..
make -j 4
make install
If you run into any failure

Here is a quick check before you cleanup build/ and retry: try cmake instead of ccmake and see if you get the following logs:

--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   YES
--       avformat:                  YES
--       avutil:                    YES
--       swscale:                   YES
--       avresample:                YES
--     GStreamer:                   YES (1.10.4)
--     v4l/v4l2:                    YES (linux/videodev2.h)
  • If FFMPEG is not discovered, check if you have set up FFmpeg environment correctly.
  • IF GStreamer is not discovered, you should do yum install gstreamer.

OpenFace

(Not for faint-hearted ones)

git clone https://github.com/TadasBaltrusaitis/OpenFace.git
cd OpenFace && mkdir build && cd build
ccmake -DOpenCV_DIR=~/opencv-4.1.0/build/ \
CMAKE_CXX_COMPILER=~/gcc-9.3.0/gccbuild/bin/g++ -DCMAKE_C_COMPILER=~/gcc-9.3.0/gccbuild/bin/gcc \
-Ddlib_DIR=~/dlib-19.13/build/lib64/cmake/dlib/ \
-DBoost_INCLUDE_DIRS=~/boost_1_70_0/build/include -DBoost_LIBRARY_DIRS=~/boost_1_70_0/build/lib/ ..
make -j 4

Tests

Test your installation using actual-openface-installation #4. Note that video should pop up for first (FaceLandmarkVid) and fourth (FeatureExtraction) tests.

Appendix

OpenFace Docker container

You should setup $DISPLAY when launching OpenFace Doker container for first (FaceLandmarkVid) and fourth (FeatureExtraction) tests:

docker run --rm -ti -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY --privileged algebr/openface

However, I got too many thread_release_buffer calls! error from Docker container which presumably failed FaceLandmarkVidMulti. Given that, the Docker container would not probably be useful.

HAAR face detector

It is safe to ignore the warning:

Could not find the HAAR face detector location

Installation issues

ERIS modules

The following on ERIS cluster were helpful to realize how LD_LIBRARY_PATH should be defined for GCC and Boost

module show Boost/1.61.0-foss-2016a
module show GCCcore/7.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment