mpatacchiola/DeepGaze のインストールと動作確認(頭部の姿勢推定)(Python 3.7, TensorFlow 1.15.5 を使用)(Windows 上)
【目次】
手順の要点: 前準備として,NVIDIA CUDA 10.0, NVIDIA cuDNN 7.6.5, Python 3.7, TensorFlow 1.15.5 等をインストール.
ソフトウェア等の利用条件等は,利用者で確認すること.
謝辞:ソフトウェアの作者に感謝します
前準備
Python 3.7,Git のインストール(Windows 上)
Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム.
【手順】
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
次のコマンドを実行
次のコマンドは,Python ランチャーとPython 3.7とGitをインストールし,Gitにパスを通すものである.
次のコマンドでインストールされるGitは 「git for Windows」と呼ばれるものであり, Git,MinGW などから構成されている.
winget install --scope machine Python.Launcher winget install --scope machine Python.Python.3.7 winget install --scope machine Git.Git powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\Git\cmd\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
【関連する外部ページ】
- Python の公式ページ: https://www.python.org/
- Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
【関連項目】 Python, Git バージョン管理システム, Git の利用
TensorFlow 1.15.5, Keras 2.3.1 のインストール
py -3.7 -m pip uninstall -y tensorflow tensorflow-cpu tensorflow-gpu tensorflow-intel tensorflow-text tensorflow-estimator tf-models-official tf_slim tensorflow_datasets tensorflow-hub keras keras-tuner keras-visualizer scipy pandas matplotlib
# TensorFlow 1.15.5 のため numpy, protobuf の古いバージョンを使用.エラーが出にくいと考えられる numpy 1.16.2, protobuf 3.19.4 を使用
py -3.7 -m pip install -U numpy==1.16.2 protobuf==3.19.4 tensorflow-gpu==1.15.5 keras==2.3.1 scipy==1.5.4
py -3.7 -m pip install git+https://github.com/tensorflow/docs
py -3.7 -m pip install git+https://github.com/tensorflow/examples.git
py -3.7 -m pip install git+https://www.github.com/keras-team/keras-contrib.git
mpatacchiola/DeepGaze のインストール
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
- Windows で,コマンドプロンプトを管理者として実行.
- DeepGaze のインストールディレクトリを空にしておく
cd /d c:%HOMEPATH% rmdir /s /q deepgaze
- DeepGaze のインストール
cd /d c:%HOMEPATH% git clone https://github.com/mpatacchiola/deepgaze cd deepgaze py -3.7 setup.py build py -3.7 setup.py install
- 終了の確認
エラーメッセージが出ていないこと.
mpatacchiola/DeepGaze を用いて頭部の姿勢推定を行ってみる
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
サンプルプログラムを動かしてみる
- Windows では,コマンドプロンプトを実行.
- 次のコマンドを実行
cd /d c:%HOMEPATH% cd deepgaze\examples\ex_cnn_head_pose_estimation_images py -3.7 ex_cnn_head_pose_estimation_images.py
- 結果を確認
動画ファイルで動かす
ここで使用する mp4 形式動画ファイル: sample1.mp4
- Windows では,コマンドプロンプトを実行.
- 作業用のディレクトリ(フォルダ)として,c:\imageを作り,
sample1.mp4 を,c:\image の下にダウンロード
mkdir c:\image cd c:\image curl -O https://www.kkaneko.jp/sample/face/sample1.mp4
- %HOMEPATH%\deepgaze の下の examples の下の
ex_cnn_head_pose_estimation_images の下にあるファイルを使いたい
ファイルのコピー
cd /d c:%HOMEPATH% cd deepgaze\examples\ex_cnn_head_pose_estimation_images copy ex_cnn_head_pose_estimation_images.py a.py
- いまコピーしてできた新しいファイル a.py をエディタで開く
notepad a.py
-
OpenCV による動画表示を行うために,
このプログラムファイルの後半部分を次のように書き換え
v = cv2.VideoCapture("c:/image/sample1.mp4") while(v.isOpened()): r, img = v.read() if ( r == False ): break img = cv2.resize(img, (480, 480)) roll = my_head_pose_estimator.return_roll(img) # Evaluate the roll angle using a CNN pitch = my_head_pose_estimator.return_pitch(img) # Evaluate the pitch angle using a CNN yaw = my_head_pose_estimator.return_yaw(img) # Evaluate the yaw angle using a CNN print("roll %s, pitch %s, yaw %s" % ( str(roll[0,0,0]), str(pitch[0,0,0]), str(yaw[0,0,0]) ) ) cv2.imshow("", img) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
編集したら,ファイルを「上書き保存」する
- Python プログラムの実行
py -3.7 a.py
- 結果の確認
ビデオカメラで確認
-
OpenCV による動画表示を行うために,
次のように書き換える.書き換えたら保存する
v = cv2.VideoCapture(0) while(v.isOpened()): r, img = v.read() if ( r == False ): break img = cv2.resize(img, (480, 480)) roll = my_head_pose_estimator.return_roll(img) # Evaluate the roll angle using a CNN pitch = my_head_pose_estimator.return_pitch(img) # Evaluate the pitch angle using a CNN yaw = my_head_pose_estimator.return_yaw(img) # Evaluate the yaw angle using a CNN print("roll %s, pitch %s, yaw %s" % ( str(roll[0,0,0]), str(pitch[0,0,0]), str(yaw[0,0,0]) ) ) cv2.imshow("", img) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
- ファイルを「上書き保存」する
-
Python プログラムの実行
py -3.7 a.py
- 結果の確認