Windows での Git のインストール: 別ページ »で説明
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明
【サイト内の関連ページ】
Python のまとめ: 別ページ »にまとめ
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Windows での Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN v8.6 のインストールと動作確認: 別ページ »で説明
【関連する外部ページ】
コマンドプロンプトを管理者として実行: 別ページ »で説明
PyTorch のページ: https://pytorch.org/index.html
次のコマンドは, 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())"
インストールの方法は複数ある. ここでは, NVIDIA CUDA ツールキットを使うことも考え, インストールしやすい方法として,ソースコードからビルドしてインストールする方法を案内している.
MMCV のインストールを行う.
インストールの方法は複数ある. ここでは, NVIDIA CUDA ツールキットを使うことも考え, インストールしやすい方法として,ソースコードからビルドしてインストールする方法を案内している.
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -c "import torch; TORCH_VERSION = '.'.join(torch.__version__.split('.')[:2]); print(TORCH_VERSION)"
このとき,実際には 11.8 をインストールしているのに,「cu117」のように古いバージョンが表示されることがある.このような場合は,気にせずに続行する.
python -c "import torch; CUDA_VERSION = torch.__version__.split('+')[-1]; print(CUDA_VERSION)"
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
python -c "from mmcv.ops import get_compiling_cuda_version, get_compiler_version; print(get_compiling_cuda_version()); print(get_compiler_version())"
コマンドプロンプトを管理者として実行: 別ページ »で説明
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__)"
(途中省略)
cd %HOMEPATH% rmdir /s /q mmpose git clone https://github.com/open-mmlab/mmpose.git cd mmpose python setup.py develop
python -m pip install git+https://github.com/JonathonLuiten/TrackEval.git
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
コマンドプロンプトを管理者として実行: 別ページ »で説明
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
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
処理するビデオファイル名は, ここでは,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
関節角度の計算は,次の手順になる.
3つの関節が必要.13, 8, 16 を選択
import math
vector1 = (x13 - x8, y13 - y8, z13 - z8)
length1 = math.sqrt(vector1[0]**2 + vector1[1]**2 + vector1[2]**2)
vector2 = (x16 - x8, y16 - y8, z16 - z8)
length2 = math.sqrt(vector2[0]**2 + vector2[1]**2 + vector2[2]**2)
(x13, y13, z13)は13番目の関節の座標であり、(x8, y8, z8)は8番目の関節の座標であり, (x16, y16, z16)は16番目の関節の座標
dot_product = vector1[0] * vector2[0] + vector1[1] * vector2[1] + vector1[2] * vector2[2]
angle = math.acos(dot_product / (length1 * length2))
ここで、length1とlength2は、前の手順で計算した2つのベクトルの大きさです。
関節角度の計算を行うために, まず,先ほどのプログラムをエディタで開く.
cd %HOMEPATH% cd mmpose cd demo notepad body3d_two_stage_video_demo.py
先ほどのプログラムを次のように書き換える.書き換えが終わったら上書き保存
import math
if pose_lift_results_vis: first_obj = pose_lift_results_vis[0] keypoints = first_obj['keypoints'] keypoints_3d = first_obj['keypoints_3d'] vector1 = (keypoints_3d[13][0] - keypoints_3d[8][0], keypoints_3d[13][1] - keypoints_3d[8][1], keypoints_3d[13][2] - keypoints_3d[8][2]) length1 = math.sqrt(vector1[0]**2 + vector1[1]**2 + vector1[2]**2) vector2 = (keypoints_3d[16][0] - keypoints_3d[8][0], keypoints_3d[16][1] - keypoints_3d[8][1], keypoints_3d[16][2] - keypoints_3d[8][2]) length2 = math.sqrt(vector2[0]**2 + vector2[1]**2 + vector2[2]**2) dot_product = vector1[0] * vector2[0] + vector1[1] * vector2[1] + vector1[2] * vector2[2] angle = math.acos(dot_product / (length1 * length2)) degree = angle * 180 / math.pi print("degree = ", round(degree, 1))
先ほどと同じプログラムを,同じオプションで実行
処理するビデオファイル名は, ここでは,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
demo\resources\demo.mp4
vis_results\vis_demo.mp4