openpose-plus のインストール(trustcoinmining/openpose-plus,TensorFlow 1.15.5 を使用)(書きかけ)

URL: https://github.com/trustcoinmining/openpose-plus

前準備

Python 3.7 のインストール

以下のいずれかの方法で Python 3.7 をインストールする。

方法1:winget によるインストール

Python がインストール済みの場合、この手順は不要である。管理者権限コマンドプロンプトで以下を実行する。管理者権限のコマンドプロンプトを起動するには、Windows キーまたはスタートメニューから「cmd」と入力し、表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する。

winget install -e --id Python.Python.3.7 --scope machine --silent --accept-source-agreements --accept-package-agreements --override "/quiet InstallAllUsers=1 PrependPath=1 AssociateFiles=1 InstallLauncherAllUsers=1"

--scope machine を指定することで、システム全体(全ユーザー向け)にインストールされる。このオプションの実行には管理者権限が必要である。インストール完了後、コマンドプロンプトを再起動すると PATH が自動的に設定される。

方法2:インストーラーによるインストール

  1. Python 公式サイト(https://www.python.org/downloads/)にアクセスし、「Download Python 3.x.x」ボタンから Windows 用インストーラーをダウンロードする。
  2. ダウンロードしたインストーラーを実行する。
  3. 初期画面の下部に表示される「Add python.exe to PATH」に必ずチェックを入れてから「Customize installation」を選択する。このチェックを入れ忘れると、コマンドプロンプトから python コマンドを実行できない。
  4. 「Install Python 3.xx for all users」にチェックを入れ、「Install」をクリックする。

インストールの確認

コマンドプロンプトで以下を実行する。

python --version

バージョン番号(例:Python 3.7.x)が表示されればインストール成功である。「'python' は、内部コマンドまたは外部コマンドとして認識されていません。」と表示される場合は、インストールが正常に完了していない。

AIエディタ Windsurf のインストール

Pythonプログラムの編集・実行には、AIエディタの利用を推奨する。ここでは、Windsurfのインストールを説明する。

Windsurf がインストール済みの場合、この手順は不要である。管理者権限コマンドプロンプトで以下を実行する。管理者権限のコマンドプロンプトを起動するには、Windows キーまたはスタートメニューから「cmd」と入力し、表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する。

winget install -e --id Codeium.Windsurf --scope machine --accept-source-agreements --accept-package-agreements --override "/VERYSILENT /NORESTART /MERGETASKS=!runcode,addtopath,associatewithfiles,!desktopicon"
powershell -Command "$env:Path=[System.Environment]::GetEnvironmentVariable('Path','Machine')+';'+[System.Environment]::GetEnvironmentVariable('Path','User'); windsurf --install-extension MS-CEINTL.vscode-language-pack-ja --force; windsurf --install-extension ms-python.python --force"

--scope machine を指定することで、システム全体(全ユーザー向け)にインストールされる。このオプションの実行には管理者権限が必要である。インストール完了後、コマンドプロンプトを再起動すると PATH が自動的に設定される。

関連する外部ページ

Windsurf の公式ページ: https://windsurf.com/

Gitのインストール

以下のコマンドを管理者権限コマンドプロンプトで実行する (手順:Windowsキーまたはスタートメニュー → cmd と入力 → 右クリック → 「管理者として実行」)。管理者権限は、wingetの--scope machineオプションでシステム全体にソフトウェアをインストールするために必要となる。

REM Git をシステム領域にインストール
winget install --scope machine --id Git.Git -e --silent --accept-source-agreements --accept-package-agreements
REM Git のパス設定
set "GIT_PATH=C:\Program Files\Git\cmd"
for /f "skip=2 tokens=2*" %a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path') do set "SYSTEM_PATH=%b"
if exist "%GIT_PATH%" (
    echo "%SYSTEM_PATH%" | find /i "%GIT_PATH%" >nul
    if errorlevel 1 setx PATH "%GIT_PATH%;%SYSTEM_PATH%" /M >nul
)

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

このページで説明のために使用する画像

画像ファイル fruits.jpg, home.jpg のダウンロード

画像ファイル fruits.jpg, home.jpg のダウンロードは, Windows でコマンドプロンプトを管理者として開き 次のコマンドを実行する.

mkdir c:\image
cd c:\image
curl -L https://github.com/opencv/opencv/blob/master/samples/data/fruits.jpg?raw=true -o fruits.jpg
curl -L https://github.com/opencv/opencv/blob/master/samples/data/home.jpg?raw=true -o home.jpg

上のコマンドがうまく実行できないときは, 別ページを参考にダウンロードを行う.

https://github.com/opencv/opencv/tree/master/samples/data で公開されている fruits.jpg, home.jpg を使用する(謝辞:画像の作者に感謝します)

openpose-plus のインストール(trustcoinmining/openpose-plus を使用)

  1. 以下の手順を管理者権限コマンドプロンプトで実行する (手順:Windowsキーまたはスタートメニュー → cmd と入力 → 右クリック → 「管理者として実行」)。
  2. cython, pycocotools のインストール
    py -3.7 -m pip install -U pip setuptools
    py -3.7 -m pip install -U cython
    py -3.7 -m pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
    py -3.7 -m pip install "easydict>=1.8,<=1.10"
    py -3.7 -m pip install "opencv-python>=3.4,<3.5"
    py -3.7 -m pip install "nltk>=3.3,<3.4"
    
  3. TensorFlow 1.15.5 GPU 版 のインストール

    「tf-models-official==2.1.0.dev2」はインストール時のエラー抑止のため.

    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
    py -3.7 -m pip install -U tensorflow-gpu==1.15.5 tf-models-official==2.1.0.dev2 tf_slim tensorflow_datasets tensorflow-hub keras keras-tuner keras-visualizer
    py -3.7 -c "import tensorflow as tf; print(tf.__version__)"
    py -3.7 -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())"
    
  4. openpose-plus のインストール
    cd /d c:%HOMEPATH%
    rmdir /s /q openpose-plus
    git clone --recursive https://github.com/trustcoinmining/openpose-plus
    cd openpose-plus
    rmdir /s /q build
    mkdir build
    cd build
    cmake -G "Visual Studio 15 2017" -A x64 -T host=x64 ..
    cmake --build . --config Release --target INSTALL -- /m:4