次で配布されているソフトウエア
https://github.com/chen0040/keras-face
これは,顔検証と顔識別のソフトウエア.DeepFace, VGG16 + Siamese を使用.
手順の要点: Python 3.6, TensorFlow 1.15 を使う.
ソフトウエア等の利用条件等は,利用者で確認すること.
謝辞:ソフトウエアの作者に感謝します
TensorFlow 1.15 を使う.
「Visual Studio Community 2019 vesion 16.2, マイクロソフト C++ ビルドツールのインストール(Windows 上)」で説明している.
すでに TensorFlow 2 を使っている,あるいは使う予定ということがありえる. 単純には,TensorFlow 2 と TensorFlow 1.15 を共存させて Python で使うということはできないが, 少しの手間で,共存できるようになる. そこで,TensorFlow 2 とTensorFlow 1.15 の共存を前提として, TensorFlow 1.15 のインストールを行う.
【Python 開発環境のインストール】
Python を使うときは,Python開発環境や Python コンソール(Jupyter Qt Console,Spyder,PyCharm,PyScripter など)の利用も便利である
Windows, Ubuntu での Python 開発環境,Python コンソール(Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, spyder)のインストール: 別ページで,インストール手順を説明している.
Windows でのPython3.6,TensorFlow 1.15 のインストール:別ページで説明している.
すでにPython 3.9 あるいは Python 3.8 をインストールしている,あるいは,インストール予定という場合を想定し, あとのトラブルが起きにくい,そして,簡単に運用できるように 「Python 3.6 をインストールし,その上に,TensorFlow 1.15.5 をインストールする」という手順を案内している.
Ubuntu でのPython,TensorFlow 1.15 のインストール:別ページで案内している.
Ubuntu のシステム Python に影響を与えないように,隔離された Python 3.6 仮想環境の新規作成し,その上にTensorFlow 1.15.5 をインストールするという手順(venv を使用)(Ubuntu 上)を案内している.
Git の URL: https://git-scm.com/
sudo apt -y update sudo apt -y install git
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
mkdir c:\pytools cd c:\pytools rmdir /s /q keras-face
git clone https://github.com/chen0040/keras-face cd keras-face
py -3.6 -m pip install opencv-python numpy scipy pillow pandas h5py matplotlib scikit-learn tensorflow-gpu==1.15.5 keras==2.3.1
c:\pytools\keras-face\demo にあるファイルを丸ごと、
c:\pytools\keras-faceに移動
その結果、次のようになる
エラーの回避のため.keras_face\library\face_net.py を次のように書き換える
「np.set_printoptions(threshold=np.nan)」を削除
cd c:\pytools cd keras-face
このプログラムは camera_0.jpg が誰なのかを顔識別する。
GitHub の chen0040/keras-face の Web ページに記載されている次のプログラムを実行
py -3.6 を使用.
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 法(つまり別もの)
データのダウンロードと、学習を行うので時間がかかる
py -3.6 を使用.
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()
顔識別の結果が表示される