金子邦彦研究室人工知能Windows でのインストールと動作確認(人工知能関係)MMPose のインストールと動作確認(姿勢推定,関節角度の推定)(PyTorch,Python を使用)(Windows 上)

MMPose のインストールと動作確認(姿勢推定,関節角度の推定)(PyTorch,Python を使用)(Windows 上)

MMPose は, OpenMMLab の構成物で,2次元の姿勢推定,3次元の姿勢推定の機能を提供する.

【目次】

  1. 前準備
  2. MMPose のインストール(Windows 上)
  3. MMPose の動作確認(Windows 上)

前準備

Git のインストール(Windows 上)

Windows での Git のインストール: 別ページ »で説明

関連する外部ページ

Git の公式ページ: https://git-scm.com/

Python のインストール(Windows 上)

Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明

サイト内の関連ページ

Python のまとめ: 別ページ »にまとめ

関連する外部ページ

Python の公式ページ: https://www.python.org/

Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット,NVIDIA cuDNN のインストール(Windows 上)

Windows での Build Tools for Visual Studio 2022NVIDIA ドライバNVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN v8.6 のインストールと動作確認: 別ページ »で説明

関連する外部ページ

PyTorch のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. PyTorch のページを確認

    PyTorch のページ: https://pytorch.org/index.html

  3. 次のようなコマンドを実行(実行するコマンドは,PyTorch のページの表示されるコマンドを使う).

    次のコマンドは, PyTorch 2.0 (NVIDIA CUDA 11.8 用) をインストールする. 事前に NVIDIA CUDA のバージョンを確認しておくこと(ここでは,NVIDIA CUDA ツールキット 11.8 が前もってインストール済みであるとする).

    python -m pip install -U pip
    python -m pip install -U torch torchvision torchaudio numpy numba --index-url https://download.pytorch.org/whl/cu118
    python -c "import torch; print(torch.__version__, torch.cuda.is_available())" 
    

    (途中省略)
    [image]

MMPose のインストール(Windows 上)

インストールの方法は複数ある. ここでは, NVIDIA CUDA ツールキットを使うことも考え, インストールしやすい方法として,ソースコードからビルドしてインストールする方法を案内している.

MMCV のインストール(Windows 上)

MMCV のインストールを行う.

インストールの方法は複数ある. ここでは, NVIDIA CUDA ツールキットを使うことも考え, インストールしやすい方法として,ソースコードからビルドしてインストールする方法を案内している.

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. PyTorch がインストールできていることを確認するために,PyTorch のバージョンを表示
    python -c "import torch; TORCH_VERSION = '.'.join(torch.__version__.split('.')[:2]); print(TORCH_VERSION)"
    

    [image]
  3. PyTorch が NVIDIA CUDA ツールキットを認識できていることを確認するために, PyTorch が認識しているNVIDIA CUDA ツールキット のバージョンを表示

    このとき,実際には 11.8 をインストールしているのに,「cu117」のように古いバージョンが表示されることがある.このような場合は,気にせずに続行する.

    python -c "import torch; CUDA_VERSION = torch.__version__.split('+')[-1]; print(CUDA_VERSION)"
    

    [image]
  4. MMCV 1.6.2 のインストール

    MMTracking が MMCV 1.6.2 に依存している (2022/12). MMTracking を利用するので MMCV 1.6.2 をインストール

    https://mmcv.readthedocs.io/en/latest/get_started/installation.html に記載の手順による

    python -m pip install -U pip
    python -m pip install -U opencv-python
    python -m pip install mmcv-full==1.6.2
    

    [image]
  5. MMCV をインストールできたことの確認

    python -c "from mmcv.ops import get_compiling_cuda_version, get_compiler_version; print(get_compiling_cuda_version()); print(get_compiler_version())"
    

    [image]

MIM,MMClassification,MMSegmentation,MMDetection,MMTracking,MMPose のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. MIM, MMClassification, MMSegmentation, MMDetection, MMTracking, MMPose のインストール.

    python -m pip install -U git+https://github.com/open-mmlab/mim.git
    python -m pip install -U git+https://github.com/open-mmlab/mmclassification.git
    python -m pip install -U git+https://github.com/open-mmlab/mmdetection.git
    python -m pip install -U git+https://github.com/open-mmlab/mmsegmentation.git
    python -m pip install -U git+https://github.com/open-mmlab/mmtracking.git
    python -m pip install -U git+https://github.com/open-mmlab/mmpose.git
    python -m pip install -U numpy
    python -m pip install -U scipy
    python -c "import mmcls; print(mmcls.__version__)"
    python -c "import mmdet; print(mmdet.__version__)"
    python -c "import mmseg; print(mmseg.__version__)"
    python -c "import mmtrack; print(mmtrack.__version__)"
    python -c "import mmpose; print(mmpose.__version__)"
    

    (途中省略)

    [image]
  3. MMPose のファイルをダウンロードし,使える状態にする

    cd %HOMEPATH%
    rmdir /s /q mmpose
    git clone https://github.com/open-mmlab/mmpose.git
    cd mmpose
    python setup.py develop
    
  4. MOT evaluation のインストール

    python -m pip install git+https://github.com/JonathonLuiten/TrackEval.git
    

MMPose の動作確認(Windows 上)

  1. 次のコマンドを実行
    cd %HOMEPATH%
    cd mmpose
    python demo\top_down_img_demo_with_mmdet.py ^
        demo\mmdetection_cfg\faster_rcnn_r50_fpn_coco.py ^
        https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth ^
        configs\body\2d_kpt_sview_rgb_img\topdown_heatmap\coco\hrnet_w48_coco_256x192.py ^
        https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth ^
        --img-root tests\data\coco\ ^
        --img 000000000785.jpg ^
        --out-img-root vis_results
    

    [image]
  2. vis_results の下に結果が保存されるので確認

    [image]

    [image]

ビデオファイルから3次元の姿勢推定を行ってみる(MMPose,学習済みモデルを使用)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. MMPose のソースコード等のファイルをダウンロード

    cd %HOMEPATH%
    rmdir /s /q  mmpose
    git clone https://github.com/open-mmlab/mmpose.git
    cd mmpose
    python -m pip install -r requirements.txt
    python setup.py develop
    
  3. 使用するプログラムの準備

    MMPose の機能を利用.

    公式ページの https://github.com/open-mmlab/mmpose/blob/master/demo/docs/3d_human_pose_demo.md で説明されているプログラムを使用.

    3次元の座標値を表示するように, 次のように, ファイル名: body3d_two_stage_video_demo.py のファイルの 475 行目に,print(pose_lift_results_vis) の 1行を追加.字下げも正しく.

    書き換えが終わったら上書き保存

    cd %HOMEPATH%
    cd mmpose
    cd demo
    notepad body3d_two_stage_video_demo.py
    

    [image]

    [image]
  4. 姿勢推定の実行

    処理するビデオファイル名は, ここでは,demo/resources/demo.mp4 にしている.自分が処理したいものを設定すること.

    cd %HOMEPATH%
    cd mmpose
    python demo/body3d_two_stage_video_demo.py ^
        demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py ^
        https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth ^
        configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/coco/hrnet_w48_coco_256x192.py ^
        https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth ^
        configs/body/3d_kpt_sview_rgb_vid/video_pose_lift/h36m/videopose3d_h36m_243frames_fullconv_supervised_cpn_ft.py ^
        https://download.openmmlab.com/mmpose/body3d/videopose/videopose_h36m_243frames_fullconv_supervised_cpn_ft-88f5abbb_20210527.pth ^
        --video-path demo/resources/demo.mp4 ^
        --out-video-root vis_results ^
        --rebase-keypoint-height
    

    [image]
  5. 関節角度の計算

    関節角度の計算は,次の手順になる.

    関節角度の計算を行うために, まず,先ほどのプログラムをエディタで開く.

    cd %HOMEPATH%
    cd mmpose
    cd demo
    notepad body3d_two_stage_video_demo.py
    

    先ほどのプログラムを次のように書き換える.書き換えが終わったら上書き保存

  6. 姿勢推定の実行

    先ほどと同じプログラムを,同じオプションで実行

    処理するビデオファイル名は, ここでは,demo/resources/demo.mp4 にしている.自分が処理したいものを設定すること.

    cd %HOMEPATH%
    cd mmpose
    python demo/body3d_two_stage_video_demo.py ^
        demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py ^
        https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth ^
        configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/coco/hrnet_w48_coco_256x192.py ^
        https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth ^
        configs/body/3d_kpt_sview_rgb_vid/video_pose_lift/h36m/videopose3d_h36m_243frames_fullconv_supervised_cpn_ft.py ^
        https://download.openmmlab.com/mmpose/body3d/videopose/videopose_h36m_243frames_fullconv_supervised_cpn_ft-88f5abbb_20210527.pth ^
        --video-path demo/resources/demo.mp4 ^
        --out-video-root vis_results ^
        --rebase-keypoint-height
    

    [image]
  7. 元のビデオの確認

    demo\resources\demo.mp4
    

    [image]
  8. 結果の確認

    vis_results\vis_demo.mp4
    

    [image]