Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.
【サイト内の関連ページ】
Windows での Git のインストール: 別ページ »で説明している.
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
【サイト内の関連ページ】
NVIDIA グラフィックスボードを搭載しているパソコンの場合には, NVIDIA ドライバ, NVIDIA CUDA ツールキット, NVIDIA cuDNN のインストールを行う.
【関連する外部ページ】
コマンドプロンプトを管理者として実行: 別ページ »で説明
PyTorch のページ: https://pytorch.org/index.html
次のコマンドを実行することにより, PyTorch 2.3 (NVIDIA CUDA 11.8 用)がインストールされる. 但し,Anaconda3を使いたい場合には別手順になる.
事前に NVIDIA CUDA のバージョンを確認しておくこと(ここでは,NVIDIA CUDA ツールキット 11.8 が前もってインストール済みであるとする).
PyTorch で,GPU が動作している場合には,「torch.cuda.is_available()」により,True が表示される.
python -m pip install -U --ignore-installed pip python -m pip uninstall -y torch torchvision torchaudio torchtext xformers python -m pip install -U torch torchvision torchaudio numpy --index-url https://download.pytorch.org/whl/cu118 python -c "import torch; print(torch.__version__, torch.cuda.is_available())"
Anaconda3を使いたい場合には, Anaconda プロンプト (Anaconda Prompt) を管理者として実行し, 次のコマンドを実行する. (PyTorch と NVIDIA CUDA との連携がうまくいかない可能性があるため,Anaconda3を使わないことも検討して欲しい).
conda install -y pytorch torchvision torchaudio pytorch-cuda=11.8 cudnn -c pytorch -c nvidia py -c "import torch; print(torch.__version__, torch.cuda.is_available())"
【サイト内の関連ページ】
【関連する外部ページ】
インストールの方法は複数ある. ここでは, 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)"
インストール手順は, https://mmcv.readthedocs.io/en/latest/get_started/installation.html に記載の手順による
python -m pip install -U --ignore-installed pip python -m pip uninstall -y openmim mmcv mmcv-full opencv-python opencv-python-headless python -m pip install -U openmim opencv-python cd %USERPROFILE% rmdir /s /q mmpose git clone https://github.com/open-mmlab/mmpose.git cd mmpose mim uninstall -y mmpose pip install -r requirements.txt mim install -e . mim list
python -m pip install git+https://github.com/JonathonLuiten/TrackEval.git
cd %USERPROFILE% cd mmpose python demo\topdown_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_keypoint/topdown_heatmap/coco/td-hm_hrnet-w48_8xb32-210e_coco-256x192.py ^ https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth ^ --input tests\data\coco\000000000785.jpg ^ --output-root vis_results
コマンドプロンプトを管理者として実行: 別ページ »で説明
cd %USERPROFILE% 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 %USERPROFILE% cd mmpose cd demo notepad body3d_two_stage_video_demo.py
処理するビデオファイル名は, ここでは,demo/resources/demo.mp4 にしている.自分が処理したいものを設定すること.
cd %USERPROFILE% 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 %USERPROFILE% 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 %USERPROFILE% 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