【OpenFace】

OpenFace:

http://cmusatyalab.github.io/openface/


一、什麼是Openface?

Openface是一個基於深度神經網絡的開源人臉識別系統。該系統基於谷歌的文章FaceNet: A Unified Embedding for Face Recognition and Clustering。Openface是卡內基梅隆大學的 Brandon Amos主導的。

 

官方地址:http://cmusatyalab.github.io/openface/

代碼:https://github.com/cmusatyalab/openface

二、Openface環境搭建

系統:Ubuntu 14.04 64位桌面操作系統

參考:http://cmusatyalab.github.io/openface/setup/

1、Ubuntu切換root用戶

此處不詳述,如果要用普通用戶,請自行測試

參考文章:

http://blog.csdn.net/itas109/article/details/50679251

 

2、安裝前準備工作

安裝必要的程序,可以用下面的批處理,也可以一個一個的進行安裝。

 

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. #!/bin/sh  
  2. sudo apt-get install build-essential -y  
  3. sudo apt-get install cmake -y  
  4. sudo apt-get install curl -y  
  5. sudo apt-get install gfortran -y  
  6. sudo apt-get install git -y  
  7. sudo apt-get install libatlas-dev -y  
  8. sudo apt-get install libavcodec-dev -y  
  9. sudo apt-get install libavformat-dev -y  
  10. sudo apt-get install libboost-all-dev -y  
  11. sudo apt-get install libgtk2.0-dev -y  
  12. sudo apt-get install libjpeg-dev -y  
  13. sudo apt-get install liblapack-dev -y  
  14. sudo apt-get install libswscale-dev -y  
  15. sudo apt-get install pkg-config -y  
  16. sudo apt-get install python-dev -y  
  17. sudo apt-get install python-pip -y  
  18. sudo apt-get install wget -y  
  19. sudo apt-get install zip –y  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. #!/bin/sh  
  2. sudo apt-get install build-essential -y  
  3. sudo apt-get install cmake -y  
  4. sudo apt-get install curl -y  
  5. sudo apt-get install gfortran -y  
  6. sudo apt-get install git -y  
  7. sudo apt-get install libatlas-dev -y  
  8. sudo apt-get install libavcodec-dev -y  
  9. sudo apt-get install libavformat-dev -y  
  10. sudo apt-get install libboost-all-dev -y  
  11. sudo apt-get install libgtk2.0-dev -y  
  12. sudo apt-get install libjpeg-dev -y  
  13. sudo apt-get install liblapack-dev -y  
  14. sudo apt-get install libswscale-dev -y  
  15. sudo apt-get install pkg-config -y  
  16. sudo apt-get install python-dev -y  
  17. sudo apt-get install python-pip -y  
  18. sudo apt-get install wget -y  
  19. sudo apt-get install zip –y  

 

3、安裝必要的庫

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. pip2 install numpy scipy pandas  
  2. pip2 install scikit-learn scikit-image  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. pip2 install numpy scipy pandas  
  2. pip2 install scikit-learn scikit-image  


注意:

a.如果出現某一個安裝失敗的情況,可以一個一個的安裝

 

b.提高pip安裝速度

可以更換pip鏡像加快下載速度
建立./pip/pip.conf,輸入以下內容(或者其他可用鏡像):

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. [global]  
  2. timeout = 6000  
  3. index-url = http://pypi.douban.com/simple  
  4.   
  5. [install]  
  6. use-mirrors = true  
  7. mirrors = <a target=_blank href="http://pypi.douban.com/">http://pypi.douban.com/</a>  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. [global]  
  2. timeout = 6000  
  3. index-url = http://pypi.douban.com/simple  
  4.   
  5. [install]  
  6. use-mirrors = true  
  7. mirrors = <a target=_blank href="http://pypi.douban.com/">http://pypi.douban.com/</a>  

 

c.報錯:SSLError: The read operation timed out

可以用下列指令將延時加長

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. pip2 -install scikit-image --timeout 100  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. pip2 -install scikit-image --timeout 100  


 

4、安裝Torch

a.安裝依賴

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. curl -shttps://raw.githubusercontent.com/torch/ezinstall/master/install-deps  | bash –e  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. curl -shttps://raw.githubusercontent.com/torch/ezinstall/master/install-deps  | bash –e  


 

b.安裝

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. git clone https://github.com/torch/distro.git ~/torch --recursive  
  2. cd ~/torch && ./install.sh  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. git clone https://github.com/torch/distro.git ~/torch --recursive  
  2. cd ~/torch && ./install.sh  

 

c.安裝依賴

luarocks install $NAME, where $NAME is as listed below.

dpnn

nn

csvigo

cunn (使用CUDA)

fblualib  (僅爲了訓練DNN)

torchx  (僅爲了訓練DNN)

 

命令行,按照需要安裝:

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. ~/torch/install/bin/luarocks install dpnn  
  2. ~/torch/install/bin/luarocks install nn  
  3. ~/torch/install/bin/luarocks install optim  
  4. ~/torch/install/bin/luarocks install csvigo  
  5. ~/torch/install/bin/luarocks install cunn  
  6. ~/torch/install/bin/luarocks install fblualib  
  7. ~/torch/install/bin/luarocks install torchx  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. ~/torch/install/bin/luarocks install dpnn  
  2. ~/torch/install/bin/luarocks install nn  
  3. ~/torch/install/bin/luarocks install optim  
  4. ~/torch/install/bin/luarocks install csvigo  
  5. ~/torch/install/bin/luarocks install cunn  
  6. ~/torch/install/bin/luarocks install fblualib  
  7. ~/torch/install/bin/luarocks install torchx  

 

d.驗證是否安裝依賴成功

用th命令驗證

 

注意:

a.gitclone更新網絡老中斷

 

Git submodule update --init –recursive

或者torch目錄下的

Update.sh

 

建議用Update.sh解決

 

b.錯誤:

Cloning into'extra/luaffifb'...

remote:Counting objects: 918, done.

error: RPCfailed; result=56, HTTP code = 200| 0 bytes/s    

fatal: Theremote end hung up unexpectedly

fatal: earlyEOF

fatal:index-pack failed

Clone of 'https://github.com/facebook/luaffifb' intosubmodule path 'extra/luaffifb' failed

解決:

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. git config --global http.postBuffer 524288000  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. git config --global http.postBuffer 524288000  

 

5、安裝opencv

OpenCV版本爲2.4.11,下載地址:https://github.com/Itseez/opencv/archive/2.4.11.zip

編譯參考:http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html

 

a.指令下載:

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. cd ~  
  2. mkdir  -p src  
  3. cd  src  
  4. curl  -L https://github.com/Itseez/opencv/archive/2.4.11.zip -o ocv.zip  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. cd ~  
  2. mkdir  -p src  
  3. cd  src  
  4. curl  -L https://github.com/Itseez/opencv/archive/2.4.11.zip -o ocv.zip  


 

b.解壓:

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. unzip  ocv.zip  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. unzip  ocv.zip  

 

c.編譯:

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. cd  opencv-2.4.11  
  2. mkdir  release  
  3. cd  release  
  4. cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..  
  5. make  -j8  
  6. make  install  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. cd  opencv-2.4.11  
  2. mkdir  release  
  3. cd  release  
  4. cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..  
  5. make  -j8  
  6. make  install  

 

d.驗證

import cv2 


6、安裝dlib

dlib v18.16下載地址:https://github.com/davisking/dlib/releases/download/v18.16/dlib-18.16.tar.bz2

 

a.安裝編譯

[html] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. mkdir -p ~/src  
  2. cd ~/src tar xf dlib-18.16.tar.bz2  
  3. cd dlib-18.16/python_examples  
  4. mkdir build  
  5. cd build  
  6. cmake ../../tools/python  
  7. cmake --build . --config Release  
  8. cp dlib.so /usr/local/lib/python2.7/dist-packages  
[html] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. mkdir -p ~/src  
  2. cd ~/src tar xf dlib-18.16.tar.bz2  
  3. cd dlib-18.16/python_examples  
  4. mkdir build  
  5. cd build  
  6. cmake ../../tools/python  
  7. cmake --build . --config Release  
  8. cp dlib.so /usr/local/lib/python2.7/dist-packages  

 

b.確保

在a中最後一條命令中,確保路徑在默認的Python路徑,可以在Python解釋器裏面用sys.path查找

For the final command, make sure the directory is in your default Python path, which can be found withsys.path in a python interpreter.

 

c.驗證

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. import dlib  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. import dlib  

 

7、Git獲取openface

a.下載Openface

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. git clone https://github.com/cmusatyalab/openface.git  
  2. git submodule init  
  3. git submodule update  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. git clone https://github.com/cmusatyalab/openface.git  
  2. git submodule init  
  3. git submodule update  

 

b.在Openface根目錄執行

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. sudo python2 setup.py install  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. sudo python2 setup.py install  

 

python2一定要確保dlib和OpenCV安裝成功

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. import cv2   
  2. import dlib  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. import cv2   
  2. import dlib  

 

c.獲取模型

[cpp] view plain copy 
  
在CODE上查看代碼片派生到我的代碼片
  1. models/get-models.sh  
[cpp] view plain copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. models/get-models.sh  

 

8、運行demo

運行demo1:

./demos/compare.pyimages/examples/{lennon*,clapton*}

運行demo2:

./demos/classifier.py infermodels/openface/celeb-classifier.nn4.small2.v1.pkl ./images/examples/carell.jpg

運行demo3:

./demos/web/start-servers.sh

 

9、demo1可用瀏覽器

可用瀏覽器:

360瀏覽器極速模式

火狐瀏覽器

搜狗瀏覽器高速模式

 

不可用瀏覽器:

Chrome谷歌瀏覽器(可能與瀏覽器更新有關係,getUserMedia())

IE覽器

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章