dlib, OpenFace and face_recognition

来源:互联网 发布:销售订单软件 编辑:程序博客网 时间:2024/06/06 01:20

How to install dlib from source

1). download dlib-19.4
2).

cd examples/mkdir buildcd build/cmake -G Xcode ...

3). Install XQuartz-2.7.11.dmg from https://www.xquartz.org/, so X server is ready
4). cd Debug/ &
./face_landmark_detection_ex shape_predictor_68_face_landmarks.dat ../../faces/*.jpg
./dnn_face_recognition_ex ../../faces/bald_guys.jpg

Install Python bindings

Basically,

  • python3 setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA

This will build libdlib.a and dlib.so from

  • Build files have been written to: ./dlib-19.7/tools/python/
Build using cmake ...Scanning dependencies of target dlib[  0%] Building CXX object dlib_build/CMakeFiles/dlib.dir/base64/base64_kernel_1.cpp.o[  1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bigint/bigint_kernel_1.cpp.o[  2%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bigint/bigint_kernel_2.cpp.o[  3%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bit_stream/bit_stream_kernel_1.cpp.o[  4%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_1.cpp.o[  5%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_2.cpp.o[  5%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_1.cpp.o[  6%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_2.cpp.o[  7%] Building CXX object dlib_build/CMakeFiles/dlib.dir/md5/md5_kernel_1.cpp.o[  8%] Building CXX object dlib_build/CMakeFiles/dlib.dir/tokenizer/tokenizer_kernel_1.cpp.o

Then Populating the distribution directory

  • ./dlib-19.7/./dist/dlib

Install dlib HEAD (w/ python bindings) - MacPorts version

1). re-install Boost binding with Python 3.5

sudo port uninstall boostport variants boostsudo port install boost -python27 +python35

2). OpenCV 3.1 has been installed before, but updated automatically

opencv @3.1.0_3+contrib+python35

3). sudo /opt/local/bin/python3.5 setup.py install –yes USE_AVX_INSTRUCTIONS –no DLIB_USE_CUDA

4). run /opt/local/bin/python3.5 and type import dlib, error:

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dlib-19.4.0-py3.5-macosx-10.11-x86_64.egg/dlib/__init__.py", line 1, in <module>    from .dlib import *ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dlib-19.4.0-py3.5-macosx-10.11-x86_64.egg/dlib/dlib.so, 2): Library not loaded: @rpath/libpng16.16.dylib  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dlib-19.4.0-py3.5-macosx-10.11-x86_64.egg/dlib/dlib.so  Reason: image not found

Error: Reason: image not found #9

face_recognition version: 1Python version: 3.6Operating System: Mac OS 10.12.3
  • just set DYLD_LIBRARY_PATH to /opt/local/lib/ where libpng16.16.dylib is located
  • How Library Search Paths Work
  • Windows Dynamic-Link Library Search Order
  • Mac Loading Code at Runtime
  • Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what’s the dynamic library search algorithm with it?
  • Using static and shared libraries across platforms

2nd Error: Reason: image not found #9

>>> import dlib>>> Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dlib-19.4.0-py3.5-macosx-10.11-x86_64.egg/dlib/__init__.py", line 1, in <module>    from .dlib import *ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dlib-19.4.0-py3.5-macosx-10.11-x86_64.egg/dlib/dlib.so, 2): Library not loaded: @rpath/libmkl_rt.dylib  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dlib-19.4.0-py3.5-macosx-10.11-x86_64.egg/dlib/dlib.so  Reason: image not found
  • Looking for Intel MKL library
  • 面向机器学习和深度学习的英特尔优化工具和框架
  • numpy/scipy and mkl
    • MKL would be a replacement for ATLAS or OpenBLAS
    • MKL is commercial
    • No Cost Options for Intel® Math Kernel Library (Intel® MKL), Support Yourself, Royalty-Free
  • NumPy/SciPy with MKL on OS X 10.11.6
    • Anaconda ships numpy/scipy with mkl by default.

FINAL SOLUTION

  • export DYLD_LIBRARY_PATH=/opt/local/lib/:/Users/leon/anaconda/lib/

Atlas compilation from mac ports

  • So either 'sudo port install atlas +nofortan' or 'sudo port install atlas +gcc48'
  • sudo port clean atlas; sudo port install atlas +gcc5

Install dlib HEAD (w/ python bindings) - Anaconda version

0). Just run pip install face_recognition (not pip3 as in webpage) will perform the following 1-4.

  • Well, actually not so sure about 1, since it appears to use Boost version from MacPorts…

1). Install Boost

2). Install OpenCV 3.1 binding with Python 3.5

  • conda install -c https://conda.binstar.org/menpo opencv3

2.1) ln -s /Users/leon/anaconda/lib/libpython3.5m.dylib /Users/leon/anaconda/lib/libpython3.5.dylib
Why only lib/libpython3.5m.dylib?
Anaconda does not provide a python-config (mine still points to the one distributed with Mac OS X 10.11):

2.2) Issue installing OPENCV with Conda #826
ImportError:
dlopen(/Users/umbi/Documents/anaconda/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so, 2): Library not loaded: @rpath/libhdf5.10.dylib
Referenced from: /Users/umbi/Documents/anaconda/lib/libopencv_hdf.3.1.0.dylib
Reason: Incompatible library version: libopencv_hdf.3.1.dylib requires version 12.0.0 or later, but libhdf5.10.dylib provides version 11.0.0

  • conda update hdf5 worked for me.

3). python3 setup.py install –yes USE_AVX_INSTRUCTIONS –no DLIB_USE_CUDA

4). run python3 and type import dlib successfully.

OpenFace now

Setup

Automated Docker Build

最简单的方法。不过要先安装配置docker环境。
下载 openface docker container

  • docker pull bamos/openface

启动

  • docker run -p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash

测试
cd /root/openface
./demos/compare.py images/examples/{lennon*,clapton*}
./demos/classifier.py infer models/openface/celeb-classifier.nn4.small2.v1.pkl ./images/examples/carell.jpg
./demos/web/start-servers.sh

Building a Docker Container

docker build -t openface .

暂时没有试。不过 Dockerfile 看起来像为安装 Ubuntu 准备的。不知道Mac下能用吗。。。

By hand

三步曲:

  • OpenCV
  • dlib
  • Torch

然后安装 openface python bindings, install the Python dependencies with:

  • sudo python2 setup.py install.

Running GUI apps with Docker

Running gtkmm inside Docker for Mac : Gtk-WARNING **: cannot open display:

  • docker run –rm -e DISPLAY=$ip:0 \
    -it -v /tmp/.X11-unix:/tmp/.X11-unix my_image /bin/bash

Running GUI apps with Docker

There are a few different options to run GUI applications inside a Docker container like using SSH with X11 forwarding, or VNC but the simplest one that I figured out was to share my X11 socket with the container and use it directly.

  • docker build -t firefox .
  • docker run -ti –rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox

Docker for Mac and GUI applications

  • brew cask install xquartz
  • open -a XQuartz
  • ip=(ifconfigen0|grepinet|awk1==”inet” {print $2}’)
  • xhost + $ip
  • docker run -d –name firefox -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix jess/firefox

Check Docker IP

docker-machine: Can’t access container’s web server from host

docker inspect –format ‘{{ .NetworkSettings.IPAddress }}’ ‘container name here’

docker commands

  • docker ps
  • docker port ‘container id’

And the winner goes to…

Docker for Mac and GUI applications

  • DISPLAY=$ip:0
  • NOT DISPLAY=$DISPLAY

Download Jessie Frazelle’s Firefox container:

  • docker build -t firefox .
  • docker run -ti –rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix b28a0dcb9f89

OR,

  • docker run -d –name firefox -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix jess/firefox

WILL ACUTALLY DOWNLOAD jess/firefox

MacBook-Pro:firefox leon$ docker run -d --name firefox -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix jess/firefoxUnable to find image 'jess/firefox:latest' locallylatest: Pulling from jess/firefox3a8649ffa174: Already exists 7b139108e3e1: Pull complete 750d66cf3374: Pull complete Digest: sha256:85a414f4a1538f18b6a65b92db5470e7c14fff27149cc56c1362f2044df044d9Status: Downloaded newer image for jess/firefox:latest93f799bb2d65c453e95d11b28ef0c51646fb05d045707b21e78b5e0b728dfb58

Torch

To install OpenFace manually one has to install Torch.

in a terminal, run the commands WITHOUT sudo
- git clone https://github.com/torch/distro.git ~/torch –recursive
- cd ~/torch; bash install-deps;
- ./install.sh
The first script installs the basic package dependencies that LuaJIT and Torch require. The second script installs LuaJIT, LuaRocks, and then uses LuaRocks (the lua package manager) to install core packages like torch, nn and paths, as well as a few other packages.

It turned out that Torch installation for Mac is based on Homebrew.

2 1
原创粉丝点击