次で配布されているソフトウエア
https://github.com/chen0040/keras-face
これは,顔検証と顔識別のソフトウエア.DeepFace, VGG16 + Siamese を使用.
手順の要点: Python 3.6, TensorFlow 1.15, Python の仮想環境(Windows では C:\venv\tf115py36)
ソフトウエア等の利用条件は,利用者で確認すること.
謝辞:ソフトウエアの作者に感謝します
※ TensorFlow 1.15.3 に対応する Python は,3.6 や 3.7 など(3.8 は対応していない)(2020/06 時点).このページでは 3.6 を使って説明する.3.7 でも同様の手順になる.
Python の URL: http://www.python.org/
インストール手順の詳細は: 別ページで説明している.
コマンドプロンプトを管理者として実行し,次のコマンドを実行.
py -3.6 -m pip install -U pip setuptools
次の手順により,システム Python とは別に,pyenv を用いて Pytnon 3.6 をインストールする.(システム Python の設定は変えたくないため).
図などの入った詳しい説明は別ページ.
sudo apt -yV install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
cd /tmp
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.bashrc
echo 'if [ -d "${PYENV_ROOT}" ]; then' >> ~/.bashrc
echo ' export PATH=${PYENV_ROOT}/bin:$PATH' >> ~/.bashrc
echo ' eval "$(pyenv init -)"' >> ~/.bashrc
echo ' eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
echo 'fi' >> ~/.bashrc
exec $SHELL -l
pyenv install 3.6.10
次のコマンドを実行.
pyenv shell 3.6.10 python -m pip install -U pip setuptools
Git の URL: https://git-scm.com/
sudo apt -yV install git
「Windows で Visual C++ ビルドツール (Build Tools) for Visual Studio 2017 のインストール(Chocolatey を利用)」で説明している.
以下,Windows に Python, git, Visual C++ ビルドツール (Build Tools) をインストール済みであるものとして説明を続ける.
※ GPU とは,グラフィックス・プロセッシング・ユニットの略で、コンピュータグラフィックス関連の機能,乗算や加算の並列処理の機能などがある.
ダウンロードページ
詳細説明
※ CUDA とは,NVIDIA社が提供している GPU 用のプラットフォームである. ダウンロードページ
TensorFlow 2.1 以上の GPU 版での,NVIDIA CUDA のバージョンは 10.1 が指定されている. TensorFlow 1.15の GPU 版での,NVIDIA CUDA のバージョンは 10.0 が指定されている. 指定されているバージョンより高いものは使わない. その根拠は次のページ. URL: https://www.tensorflow.org/install/source#common_installation_problems
詳細説明
ダウンロードページ
ダウンロードして展開(解凍)したら,パスを通しておくこと.
URL: https://www.tensorflow.org/install/source#common_installation_problems
詳細説明
最新版ではない TensorFlow を使う.そうした場合,運用を簡単にする(バージョン指定のもの間違ってアップデートしないなど)のために,venv を用いて,隔離された Python 仮想環境を作る.
今から作成する隔離された Python 仮想環境の名前と、Pythonのバージョンを決めておく
ここで行う「隔離された Python 仮想環境の新規作成と,TensorFlow 1.15.3(旧バージョン)のインストール」ついては,より詳しくは,次のページで説明している.
Windows での Python 3.6 の準備は,このページの上の方で説明している.
下の例では,隔離された Python 仮想環境のためのディレクトリを C:\venv\tf115py36に作成している.
py -3.6 -m venv C:\venv\tf115py36
venv を使い,孤立した Python 仮想環境を使っているときは,Windows でも Ubuntu でも同じで,「python -m pip install ...」. いま,venv を使っているかどうかは,プロンプトの「(venv)」で分かる.
C:\venv\tf115py36\Scripts\activate.bat python -m pip install -U pip setuptools python -m pip install -U tensorflow-gpu==1.15.3 tensorflow_datasets python -m pip install -U jupyterlab jupyter jupyter-console jupytext spyder
Ubuntu での Python 3.6 の準備は,このページの上の方で説明している.
下の例では,隔離された Python 仮想環境のためのディレクトリを ~/tf115py36に作成している.
pyenv shell 3.6.10 python -m venv ~/tf115py36
venv を使い,孤立した Python 仮想環境を使っているときは,Windows でも Ubuntu でも同じで,「python -m pip install ...」. いま,venv を使っているかどうかは,プロンプトの「(venv)」で分かる.
source ~/tf115py36/bin/activate python -m pip install -U pip setuptools python -m pip install -U tensorflow-gpu==1.15.3 tensorflow_datasets python -m pip install -U jupyterlab jupyter jupyter-console jupytext spyder
※ バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
python -c "import tensorflow as tf; print( tf.__version__ )"
TensorFlow が GPU を認識できているかの確認は,端末で,次を実行して行う.
python -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())"
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
以下,Windows での手順を示す.Ubuntu でも同様の手順になる.
cd C:\venv\tf115py36 rmdir /s /q keras-face
git clone https://github.com/chen0040/keras-face cd keras-face
python -m pip install -r requirements.txt
C:\venv\tf115py36\keras-face\demo にあるファイルを丸ごと、
C:\venv\tf115py36\keras-faceに移動
その結果、次のようになる
エラーの回避のため.keras_face\library\face_net.py を次のように書き換える
「np.set_printoptions(threshold=np.nan)」を削除
Python プログラムを動かす.
cd C:\venv\tf115py36 cd keras-face
このプログラムは camera_0.jpg が誰なのかを顔識別する。
GitHub の chen0040/keras-face の Web ページに記載されている次のプログラムを実行
from keras_face.library.face_net import FaceNet
def main():
model_dir_path = './models'
image_dir_path = "./data/images"
#
fnet = FaceNet()
fnet.load_model(model_dir_path)
#
database = {}
database["danielle"] = fnet.img_to_encoding(image_dir_path + "/danielle.png")
database["younes"] = fnet.img_to_encoding(image_dir_path + "/younes.jpg")
database["tian"] = fnet.img_to_encoding(image_dir_path + "/tian.jpg")
database["andrew"] = fnet.img_to_encoding(image_dir_path + "/andrew.jpg")
database["kian"] = fnet.img_to_encoding(image_dir_path + "/kian.jpg")
database["dan"] = fnet.img_to_encoding(image_dir_path + "/dan.jpg")
database["sebastiano"] = fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")
database["bertrand"] = fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")
database["kevin"] = fnet.img_to_encoding(image_dir_path + "/kevin.jpg")
database["felix"] = fnet.img_to_encoding(image_dir_path + "/felix.jpg")
database["benoit"] = fnet.img_to_encoding(image_dir_path + "/benoit.jpg")
database["arnaud"] = fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")
#
# verifies whether a particular camera image is a person in the image database
dist, is_valid = fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
print('camera_0.jpg is' + (' ' if is_valid else ' not ') + 'yournes')
dist, is_valid = fnet.verify(image_dir_path + "/camera_2.jpg", "kian", database)
print('camera_0.jpg is' + (' ' if is_valid else ' not ') + 'yournes')
#
# whether a particular camera image is which person in the image database (or not at all)
dist, identity = fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)
if identity is None:
print('camera_0.jpg is not found in database')
else:
print('camera_0.jpg is ' + str(identity))
if __name__ == '__main__': main()
顔識別の結果が表示される
このプログラムは、VGG16 + Siamese の学習を行うプログラムである。
※ 1つ前のプログラムは、DeepFace 法(つまり別もの)
データのダウンロードと、学習を行うので時間がかかる
from keras_face.library.siamese import SiameseFaceNet
def main():
fnet = SiameseFaceNet()
fnet.vgg16_include_top = True # default is False
#
model_dir_path = './models'
image_dir_path = "./data/images"
#
database = dict()
database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]
#
fnet.fit(database=database, model_dir_path=model_dir_path)
if __name__ == '__main__': main()
エラーメッセージが出ていないこと
このプログラムは、VGG16 + Siamese の学習の結果を使うもの
このプログラムも camera_0.jpg が誰なのかを顔識別する。
from keras_face.library.siamese import SiameseFaceNet
from functools import partial
import numpy as np
np.load = partial(np.load, allow_pickle=True)
def main():
fnet = SiameseFaceNet()
#
model_dir_path = './models'
image_dir_path = "./data/images"
fnet.load_model(model_dir_path)
#
database = dict()
database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]
#
fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
fnet.verify(image_dir_path + "/camera_2.jpg", "kian", database)
fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)
if __name__ == '__main__': main()
顔識別の結果が表示される
本サイトは金子邦彦研究室のWebページです.サイトマップは,サイトマップのページをご覧下さい. 本サイト内の検索は,サイト内検索のページをご利用下さい.
問い合わせ先: 金子邦彦(かねこ くにひこ) ![]()