Ubuntu での手順を説明する.(Windows でのインストールは別ページで説明)
Dlib は,機械学習などのライブラリ.顔認知,顔検出,顔特徴の抽出の機能もある. Dlib を用いた顔検出,顔識別,表情,顔分類,肌色領域推定については,別ページ »にまとめ
Dlib の URL: http://dlib.net
【サイト内の関連ページ】
先人に感謝.
【関連する外部ページ】
DLib 内に実装された estimator を利用(One Millisecond Face Alignment with an Ensemble of Regression Trees by Vahid Kazemi and Josephine Sullivan, CVPR 2014)
iBUG 300-W face landmark dataset を用いて学習(https://ibug.doc.ic.ac.uk/resources/facial-point-annotations/)
学習済みデータは http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 (ライセンス条項に注意すること。商用不可)
自分で学習したいときは http://dlib.net/train_shape_predictor_ex.cpp.html
LeCun, Yann, et al. "Gradient-based learning applied to document recognition." Proceedings of the IEEE 86.11 (1998): 2278-2324.
UbuntuUbuntu で OS のシステム更新を行うときは, 端末で,次のコマンドを実行する.
sudo apt -y update sudo apt -yV upgrade sudo /sbin/shutdown -r now
インストールするには,端末で,次のコマンドを実行する.
sudo apt -y install git cmake cmake-curses-gui cmake-gui curl bzip2
インストールするには,端末で,次のコマンドを実行する.
sudo apt -y install build-essential gcc g++ make libtool texinfo dpkg-dev pkg-config
端末で,次のコマンドを実行する.
sudo apt -y update sudo apt -y install libdlib-data libdlib-dev sudo apt -y install libdlib19 sudo apt -y install liblapack-dev libblas-dev
Dlib の確認のため,次の顔検出 (face detection) のプログラムを動かしてみる.
#include<dlib/image_processing/frontal_face_detector.h> #include<dlib/image_io.h> #include<iostream> using namespace dlib; using namespace std; int main(int argc, char** argv) { frontal_face_detector detector = get_frontal_face_detector(); array2d<unsigned char> img; load_image(img, argv[1]); pyramid_up(img); std::vector<rectangle> dets = detector(img); std::vector<rectangle>::iterator it; for( it = dets.begin(); it != dets.end(); it++ ) cout << *it << endl; }
このプログラムを a.cpp のようなファイル名で保存する.次のコマンドでビルドする.
g++ -o a.out a.cpp -ldlib -llapack -lblas
次のように、画像ファイル名を指定して実行する
実行の結果,顔検出 (face detection) ができていることを確認.
./a.out /usr/share/doc/libdlib19/examples/faces/2007_007763.jpg
Dlib のソースコードをダウンロードしてインストールする. このとき,Dlib の python_examples, tools のファイルを /usr/share/doc/libdlib19 以下にコピーすることも行う.
端末で,次のコマンドを実行する.
「/usr/local/cuda」のところは,NVIDIA CUDA ツールキット をインストールしたディレクトリに読み替えること.
端末で,次のコマンドを実行する.
cd /tmp sudo rm -rf dlib sudo git clone https://github.com/davisking/dlib sudo chown -R $USER dlib # cd /tmp/dlib CUDA_PATH="/usr/local/cuda" CFLAGS="-I/usr/local/cuda/include" LDFLAGS="-L/usr/local/cuda/lib64" \ sudo python3 setup.py build CUDA_PATH="/usr/local/cuda" CFLAGS="-I/usr/local/cuda/include" LDFLAGS="-L/usr/local/cuda/lib64" \ sudo python3 setup.py install cd /tmp/dlib sudo rm -f /tmp/dlib.tar sudo tar -cpf /tmp/dlib.tar ./python_examples ./tools cd /usr/share/doc/libdlib19 sudo tar -xpf /tmp/dlib.tar
端末で,次のコマンドを実行する.
エラーメッセージが出ないこと
python3 -c "import dlib;print(dlib.__version__)"
端末で,次のコマンドを実行する.することにより, 顔識別などに利用できるファイルの ダウンロードと展開(解凍)が行われる.
端末で,次のコマンドを実行する.
cd /usr/share/dlib sudo curl -O http://dlib.net/files/mmod_human_face_detector.dat.bz2 sudo curl -O http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2 sudo curl -O http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2 sudo curl -O http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 sudo bzip2 -d mmod_human_face_detector.dat.bz2 sudo bzip2 -d dlib_face_recognition_resnet_model_v1.dat.bz2 sudo bzip2 -d shape_predictor_5_face_landmarks.dat.bz2 sudo bzip2 -d shape_predictor_68_face_landmarks.dat.bz2
端末で,次のコマンドを実行する.
「/usr/local/cuda」のところは,NVIDIA CUDA ツールキット をインストールしたディレクトリに読み替えること.
sudo rm -rf /tmp/dlib.tar /tmp/tools cd /usr/share/doc/libdlib19 tar -cpf /tmp/dlib.tar ./tools cd /tmp tar -xpf /tmp/dlib.tar sudo chown -R $USER tools # cd /tmp cd tools/htmlify sudo rm -rf build mkdir build cd build cmake .. cmake --build . --config RELEASE sudo make install cd /tmp cd tools/imglab sudo rm -rf build mkdir build cd build cmake .. cmake --build . --config RELEASE sudo make install cd /tmp cd examples sudo rm -rf build mkdir build cd build cmake .. cmake --build . --config RELEASE
face_recognition の動作には,Dlib が必要
cd /usr/local sudo rm -rf face_recognition sudo apt -y install python3-click python3-numpy python3-pillow python3-scipy sudo git clone https://github.com/ageitgey/face_recognition cd face_recognition sudo python3 setup.py build sudo python3 setup.py install