Difference between revisions of "Openface: Instalasi Deep Learning di Ubuntu 16.04 Server"
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
(19 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
sudo su | sudo su | ||
+ | locale-gen id_ID.UTF-8 | ||
+ | |||
+ | apt update | ||
apt -y install git \ | apt -y install git \ | ||
libopenblas-dev libopencv-dev libboost-dev \ | libopenblas-dev libopencv-dev libboost-dev \ | ||
Line 20: | Line 23: | ||
unzip gnuplot gnuplot-x11 ipython \ | unzip gnuplot gnuplot-x11 ipython \ | ||
gcc-4.9 libgfortran-4.9-dev g++-4.9 | gcc-4.9 libgfortran-4.9-dev g++-4.9 | ||
+ | |||
+ | Lakukan 2-3 kali supaya memastikan apps di install dengan benar. | ||
==Instalasi dlib face landmark detection== | ==Instalasi dlib face landmark detection== | ||
Line 31: | Line 36: | ||
pip install scikit-image | pip install scikit-image | ||
pip install dlib | pip install dlib | ||
+ | pip install opencv-python # opencv tampaknya masih dibutuhkan | ||
+ | |||
+ | Lakukan 2-3x supaya memastikan apps di install dengan benar. | ||
==Instalasi Torch== | ==Instalasi Torch== | ||
Line 39: | Line 47: | ||
cd torch; bash install-deps; | cd torch; bash install-deps; | ||
./install.sh | ./install.sh | ||
− | |||
source ~/.bashrc | source ~/.bashrc | ||
− | apt install luarocks | + | Lakukan 2-3x untuk memastikan terinstalasi dengan baik. |
+ | |||
+ | # apt -y install luarocks | ||
# update common package ke versi terakhir | # update common package ke versi terakhir | ||
luarocks install torch | luarocks install torch | ||
Line 57: | Line 66: | ||
cd /usr/local/src | cd /usr/local/src | ||
git clone https://github.com/cmusatyalab/openface.git openface | git clone https://github.com/cmusatyalab/openface.git openface | ||
− | |||
+ | cd /usr/local/src/openface | ||
python setup.py install | python setup.py install | ||
./models/get-models.sh | ./models/get-models.sh | ||
Line 66: | Line 75: | ||
==Ambil Muka / Face yang sudah di label== | ==Ambil Muka / Face yang sudah di label== | ||
+ | |||
+ | Contoh2 foto muka untuk training. | ||
cd /usr/local/src/openface/ | cd /usr/local/src/openface/ | ||
Line 82: | Line 93: | ||
cat big_db | shuf -n 10 | xargs cp -avt training-images/ | cat big_db | shuf -n 10 | xargs cp -avt training-images/ | ||
− | + | Jika anda ingin wajah anda di recognize, tambahkan folder di training-images. Pastikan memasukan beberapa foto anda yang berisi muka anda sendirian. | |
− | + | Selanjutnya kita akan menjalankan face landmark detection untuk setiap foto yang akan | |
− | * | + | * Mendeteksi muka yang terbesar |
− | * | + | * Mendeteksi tanda2 di muka (outer eye, hidung dan bibir bawah) |
− | * Warp affine | + | * Warp affine ke canonical face |
− | * | + | * Simpan output (96x96) ke file dalam format yang mudah di akses. |
+ | Perintah yang di jalankan, | ||
− | + | cd /usr/local/src/openface/ | |
− | |||
./util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96 | ./util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96 | ||
− | + | Selanjutnya extrak fitur dari masing-masing gambar, | |
./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/ | ./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/ | ||
− | + | Langkah terakhir, train classifier untuk membuat representasi | |
./demos/classifier.py train ./generated-embeddings/ | ./demos/classifier.py train ./generated-embeddings/ | ||
− | + | File yang dihasilkan adalah classifier.pkl di folder generated-embeddings | |
− | + | Masukan foto2 referensi ke bawah folder training-images/Nama_Orang_Tersebut. | |
+ | Supaya mudah proses training ada baiknya di batch sekaligus, caranya, | ||
− | + | cd /usr/local/src/openface/ | |
− | + | rm -Rf aligned-images | |
+ | rm -Rf generated-embeddings/classifier.pkl | ||
+ | ./util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96 | ||
+ | ./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/ | ||
+ | ./demos/classifier.py train ./generated-embeddings/ | ||
− | + | ==Run== | |
− | + | Contoh run menggunakan pre-trained model yang berlokasi di celebrities folder. | |
+ | Jalankan, | ||
− | + | ./demos/classifier.py infer models/openface/celeb-classifier.nn4.small2.v1.pkl images/examples/adams.jpg | |
− | + | Hasilnya kira-kira, | |
− | . | + | Predict AmyAdams with 0.64 confidence. |
− | |||
− | + | Beberapa perintah yang menarik | |
− | + | * Mencari target operasi | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | ./demos/classifier.py infer generated-embeddings/classifier.pkl target-operasi.jpg | ||
+ | * Mengenali dari webcam (dev/video0) on VGA. | ||
+ | ./demos/classifier_webcam.py --width 640 --height 480 --captureDevice 0 generated-embeddings/classifier.pkl | ||
+ | ==Referensi== | ||
+ | * https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78#.lugw83dgc | ||
+ | * https://cmusatyalab.github.io/openface/ | ||
+ | * http://dlib.net/ | ||
+ | * http://blog.dlib.net/2014/02/dlib-186-released-make-your-own-object.html | ||
+ | * http://bamos.github.io/2016/01/19/openface-0.2.0/ | ||
+ | * https://github.com/davisking/dlib | ||
+ | * http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 | ||
+ | * https://github.com/torch/torch7/issues/966 | ||
+ | * https://wiki.debian.org/RaspberryPi/qemu-user-static | ||
+ | * https://hblok.net/blog/posts/2014/02/06/chroot-to-arm/ | ||
+ | * https://lukeplant.me.uk/blog/posts/sharing-internet-connection-to-chroot/ | ||
+ | * https://hblok.net/blog/posts/2014/02/06/chroot-to-arm/ | ||
+ | * https://github.com/cmusatyalab/openface/issues/42 | ||
==Referensi== | ==Referensi== | ||
* http://allskyee.blogspot.co.id/2017/03/face-detection-and-recognition-using.html | * http://allskyee.blogspot.co.id/2017/03/face-detection-and-recognition-using.html |
Latest revision as of 13:15, 23 May 2018
Sumber: http://allskyee.blogspot.co.id/2017/03/face-detection-and-recognition-using.html
Disini menggunakan dlib, yang katanya lebih baik daripada Haar-cascade based classifier OpenCV.
Instalasi Paket Pendukung
sudo su locale-gen id_ID.UTF-8
apt update apt -y install git \ libopenblas-dev libopencv-dev libboost-dev \ libboost-python-dev python-dev \ build-essential gcc g++ cmake apt -y install software-properties-common \ libgraphicsmagick1-dev libfftw3-dev sox libsox-dev \ libsox-fmt-all python-software-properties \ build-essential gcc g++ curl \ cmake libreadline-dev git-core libqt4-dev libjpeg-dev \ libpng-dev ncurses-dev imagemagick libzmq3-dev gfortran \ unzip gnuplot gnuplot-x11 ipython \ gcc-4.9 libgfortran-4.9-dev g++-4.9
Lakukan 2-3 kali supaya memastikan apps di install dengan benar.
Instalasi dlib face landmark detection
sudo su apt -y install build-essential cmake libgtk-3-dev \ python-pip libboost-all-dev libboost-dev apt -y install libboost-python-dev pip install numpy pip install scipy pip install scikit-image pip install dlib pip install opencv-python # opencv tampaknya masih dibutuhkan
Lakukan 2-3x supaya memastikan apps di install dengan benar.
Instalasi Torch
sudo su cd /usr/local/src git clone https://github.com/torch/distro.git torch --recursive cd torch; bash install-deps; ./install.sh source ~/.bashrc
Lakukan 2-3x untuk memastikan terinstalasi dengan baik.
# apt -y install luarocks # update common package ke versi terakhir luarocks install torch luarocks install nn luarocks install graph luarocks install cunn luarocks install cutorch luarocks install torchnet luarocks install optnet luarocks install iterm
Instalasi Openface
cd /usr/local/src git clone https://github.com/cmusatyalab/openface.git openface
cd /usr/local/src/openface python setup.py install ./models/get-models.sh pip install -r requirements.txt luarocks install csvigo luarocks install dpnn
Ambil Muka / Face yang sudah di label
Contoh2 foto muka untuk training.
cd /usr/local/src/openface/ wget http://vis-www.cs.umass.edu/lfw/lfw.tgz tar -zxvf lfw.tgz
Pilih data yang tidak lebih dari 10 muka, simpan di big_db.
cd /usr/local/src/openface/ find lfw/ -mindepth 1 -maxdepth 2 -type d -exec bash -c "echo -ne '{} '; ls '{}' | wc -l" \; | awk '$NF>10{print $1}' > big_db
Ambil 10 orang (random) dari daftar big_db, copy ke training_images
cd /usr/local/src/openface/ mkdir -p training-images cat big_db | shuf -n 10 | xargs cp -avt training-images/
Jika anda ingin wajah anda di recognize, tambahkan folder di training-images. Pastikan memasukan beberapa foto anda yang berisi muka anda sendirian.
Selanjutnya kita akan menjalankan face landmark detection untuk setiap foto yang akan
- Mendeteksi muka yang terbesar
- Mendeteksi tanda2 di muka (outer eye, hidung dan bibir bawah)
- Warp affine ke canonical face
- Simpan output (96x96) ke file dalam format yang mudah di akses.
Perintah yang di jalankan,
cd /usr/local/src/openface/ ./util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96
Selanjutnya extrak fitur dari masing-masing gambar,
./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/
Langkah terakhir, train classifier untuk membuat representasi
./demos/classifier.py train ./generated-embeddings/
File yang dihasilkan adalah classifier.pkl di folder generated-embeddings
Masukan foto2 referensi ke bawah folder training-images/Nama_Orang_Tersebut. Supaya mudah proses training ada baiknya di batch sekaligus, caranya,
cd /usr/local/src/openface/ rm -Rf aligned-images rm -Rf generated-embeddings/classifier.pkl ./util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96 ./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/ ./demos/classifier.py train ./generated-embeddings/
Run
Contoh run menggunakan pre-trained model yang berlokasi di celebrities folder. Jalankan,
./demos/classifier.py infer models/openface/celeb-classifier.nn4.small2.v1.pkl images/examples/adams.jpg
Hasilnya kira-kira,
Predict AmyAdams with 0.64 confidence.
Beberapa perintah yang menarik
- Mencari target operasi
./demos/classifier.py infer generated-embeddings/classifier.pkl target-operasi.jpg
- Mengenali dari webcam (dev/video0) on VGA.
./demos/classifier_webcam.py --width 640 --height 480 --captureDevice 0 generated-embeddings/classifier.pkl
Referensi
- https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78#.lugw83dgc
- https://cmusatyalab.github.io/openface/
- http://dlib.net/
- http://blog.dlib.net/2014/02/dlib-186-released-make-your-own-object.html
- http://bamos.github.io/2016/01/19/openface-0.2.0/
- https://github.com/davisking/dlib
- http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
- https://github.com/torch/torch7/issues/966
- https://wiki.debian.org/RaspberryPi/qemu-user-static
- https://hblok.net/blog/posts/2014/02/06/chroot-to-arm/
- https://lukeplant.me.uk/blog/posts/sharing-internet-connection-to-chroot/
- https://hblok.net/blog/posts/2014/02/06/chroot-to-arm/
- https://github.com/cmusatyalab/openface/issues/42