一津畸、前言
OpenFace是在深度學習開源框架torch上實現(xiàn)的基于python語言的人臉識別開源框架圆仔,其使用的算法是基于CVPR 2015的文章:
FaceNet: A Unified Embedding for Face Recognition and Clustering
在大數(shù)據(jù)、人工智能概念火熱的今天图贸,可以遇見不久的將來圖像識別將會是所有人工智能應用的基本功能之一,通過使用OpenFace,我們可以用最少的力氣去實現(xiàn)一個基本的人臉識別功能礁凡,這將有助于我們更好的理解人臉識別的概念和應用方法。
鑒于現(xiàn)在網上OpenFace的安裝教程基本基于Linux系統(tǒng)慧妄,而作者本人在安裝的過程中也遇到不少的坑顷牌,現(xiàn)寫下這篇教程來幫助大家更方便的安裝并使用起OpenFace。
二塞淹、OpenFace的前置組件介紹
在開始安裝OpenFace之前窟蓝,我們要了解OpenFace的前置條件。就如前言介紹的饱普,OpenFace是基于深度學習開源框架torch開發(fā)的基于python語言的人臉識別框架运挫,所以要使用OpenFace,我們需要先在系統(tǒng)中安裝了torch組件套耕。
其次谁帕,OpendFace的人臉識別和轉換是基于兩個開源架構dlib和OpenCV的預訓練好的模型的,所以要使用OpenFace冯袍,我們還需要安裝dlib和OpenCV匈挖。
三、OpenFace的前置組件安裝流程
1)安裝下載工具
在mac電腦中,沒有apt-get軟件关划,不過我們有替代品brew小染,可通過下邊的命令行代碼進行下載:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2)下載必要的系統(tǒng)工具
在命令行中輸入:
sudo brew install cmake
sudo brew install curl
sudo brew install git
sudo brew install pkg-config
sudo brew install wget
sudo brew install zip
3)安裝必要的python庫
在命令行中輸入:
brew install python
pip install numpy scipy pandas (完成)
pip install scikit-learn scikit-image (完成)
這里需要brew install python來更新一下python的原因是因為mac的python本身好像有點問題,需要更新一下才能正確更新庫
4)安裝torch
[1]安裝依賴
curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-deps ?| bash -e
[2]下載并安裝torch
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch && ./install.sh
[3]安裝torch深度學習庫
~/torch/install/bin/luarocks install dpnn
~/torch/install/bin/luarocks install nn
~/torch/install/bin/luarocks install optim
~/torch/install/bin/luarocks install csvigo
~/torch/install/bin/luarocks install torchx
~/torch/install/bin/luarocks install tds
~/torch/install/bin/luarocks install optnet
[4]驗證
將torch的bin命令位置放入~/.bash_profile中贮折,然后source ~/.bash_profile
命令行輸入 th 驗證
5)安裝opencv
[1]opencv下載并安裝
brew tap homebrew/science (接入第三方庫)
brew install opencv
[2]找到cv2.so
sudo find / -name cv2.so
[3]將opencv庫拷貝到lib目錄下
cp cv2.so /usr/local/lib/python2.7/sist-packages
[4]驗證
python
import cv2
6)安裝dlib
[1]先安裝boost(dlib庫的依賴庫)
到www.boost.org去下載boost包裤翩,解壓后到boost項目根目錄運行下邊指令
./bootstrap.sh --with-libraries=python
./b2
sudo ./b2 install
[2]安裝dlib
命令行中運行:
git clone https://github.com/davisking/dlib
cd dlib/python_examples
mkdir build
cd build
cmake ../../tools/python
cmake --build . --config Release
cp dlib.so /usr/local/lib/python2.7/sist-packages
[3]驗證
python
import dlib
四、OpenFace安裝
[1]準備工作
brew install findutils
brew install coreutils
在OSX系統(tǒng)中, 需安裝 findutils?和 coreutils调榄,因為這是Mac系統(tǒng)中對 Linux 中的 gfind 和 gwc 工具的替代踊赠,而這兩個工具在安裝過程中是需要的。
[2]下載openface
git clone https://github.com/cmusatyalab/openface/
[3]到openface根目錄下安裝依賴
sudo python2 setup.py install
[4]下載預訓練的模型
運行 models/get-models.sh
[5]下載python依賴包
pip install twisted
pip install txaio
五每庆、OpenFace使用
以上就是OpenFace的安裝過程了筐带,要嘗試著使用 OpenFace 的功能,可以在demos文件夾中找到測試腳本缤灵,詳情如下:
cd$openface_root_folder/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
希望這篇文章能幫助到大伙更方便的使用OpenFace伦籍!