InsightFace は,顔検出 (face detection),顔のアラインメント, 顔検証 (face verification), 顔識別 (face identification)の機能を持つ.
InsightFace の GitHub のページ: https://github.com/deepinsight/insightface
Ubuntu で OS のシステム更新を行うときは, 次のコマンドを実行.
Ubuntu のインストールは別ページ »で説明
sudo apt -y update sudo apt -yV upgrade sudo /sbin/shutdown -r now
インストールするには,次のコマンドを実行.
sudo apt -y install build-essential gcc g++ make libtool texinfo dpkg-dev pkg-config
Ubuntu での NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.7, NVIDIA cuDNN v8.4.1 のインストール: 別ページ »で説明
Python のインストールは行わない(Ubuntu のシステム Python を用いる.)
Python, pip のコマンドでの起動のまとめ.
Ubuntu のシステム Python を用いるとき, python, pip は,次のコマンドで起動できる.
Ubuntu での Python 開発環境(JupyterLab, spyder, nteract)のインストール: 別ページ »で説明
次のコマンドを実行.
sudo apt -y update sudo apt -y install python-is-python3 python3-dev python-dev-is-python3 python3-pip python3-setuptools python3-venv build-essential
Ubuntu での PyTorch のインストール: 別ページ »で説明
インストールするには,次のコマンドを実行.
GPU を使わない場合には「onnxruntime-gpu」でなく,「onnxruntime」をインストールすること.
sudo apt -y install python3-pil python3-numpy python3-matplotlib libopencv-dev libopencv-core-dev python3-opencv libopencv-contrib-dev opencv-data sudo pip3 install -U insightface onnxruntime-gpu
公式ページ (https://github.com/deepinsight/insightface/tree/master/python-package) に記載の,顔検出及び年齢と性別の予測のプログラムを実行する.
このプログラムは buffalo_l という名前の事前学習済みモデルを使用している.
このプログラムの実行により,result.jpg ファイルができる.
import cv2 import numpy as np import matplotlib.pyplot as plt import insightface from insightface.app import FaceAnalysis from insightface.data import get_image as ins_get_image app = FaceAnalysis(providers=['CUDAExecutionProvider', 'CPUExecutionProvider']) app.prepare(ctx_id=0, det_size=(640, 640)) img = ins_get_image('t1') faces = app.get(img) rimg = app.draw_on(img, faces) plt.style.use('default') plt.imshow(cv2.cvtColor(rimg, cv2.COLOR_BGR2RGB)) plt.show() cv2.imwrite("./result.jpg", rimg)
OpenCV による動画表示を行う.
import cv2 import numpy as np import insightface from insightface.app import FaceAnalysis from insightface.data import get_image as ins_get_image app = FaceAnalysis() app.prepare(ctx_id=0, det_size=(640, 640)) v = cv2.VideoCapture(0) while(v.isOpened()): r, f = v.read() if ( r == False ): break faces = app.get(f) rimg = app.draw_on(f, faces) cv2.imshow("", rimg) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()