HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

[NEW] 2022/12/27

NVIDIA Jetsonで StridedTransformer-Pose3D(姿勢推定)を動かす方法 NVIDIA Jetsonで StridedTransformer-Pose3D(姿勢推定)を動かす方法

(Jetson Xavier NXの JetPack 5.0.1に StridedTransformer-Pose3Dをインストールする!)

Tags: [Raspberry Pi], [電子工作], [ディープラーニング]




● Jetson Nano、Jetson Xavier NXの便利スクリプト

2020/07/03
【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト
【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト

  Jetsonの面倒な初期設定やミドルウェアのインストールを bashスクリプトの実行だけで簡単にできます


● NVIDIA Jetsonで StridedTransformer-Pose3D(姿勢推定)を動かす方法

Exploiting Temporal Contexts with Strided Transformer for 3D Human Pose Estimation

 Jetson Xavier NXの JetPack 5.0.1に StridedTransformer-Pose3Dをインストールする!

 PyTorchが必要なので下記の手順でインストールします。

[NEW] 2022/11/26
NVIDIA Jetson JetPack 5.0.1に PyTorchを NVIDIA公式の手順でインストールする方法
NVIDIA Jetson JetPack 5.0.1に PyTorchを NVIDIA公式の手順でインストールする方法

  Jetson Xavier NXの JetPack 5.0.1に PyTorchをインストールする!

 torchvisionも必要なのでインストールします。
# JetPack 5.0.2 includes CUDA 11.4.14

python -c "import torch; print (torch.__version__)"
# 1.13.0a0+936e9305.nv22.11

pip install torchvision

# UserWarning: Failed to load image Python extensionは無視して大丈夫
python -c "import torchvision; print (torchvision.__version__)"
# /home/jetson/.local/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
#   warn(f"Failed to load image Python extension: {e}")
# 0.14.1

● NVIDIA Jetsonで StridedTransformer-Pose3D(姿勢推定)をインストールする方法

# Install StridedTransformer-Pose3D
cd
git clone https://github.com/Vegetebird/StridedTransformer-Pose3D.git
cd StridedTransformer-Pose3D
python -V
pip install yacs
pip install filterpy
pip install einops

# NotImplementedError: Axes3D currently only supports the aspect argument 'auto'. You passed in 'equal'. #12
# https://github.com/Vegetebird/StridedTransformer-Pose3D/issues/12
# It works fine in matplotlib==2.2.2, may be you could try it.
pip install matplotlib==2.2.2

pip install numba
pip install scikit-image

pip install gdown
# Download pretrained model
python

import gdown

# Download pretrained model
# https://drive.google.com/drive/folders/13p62U_f5Z5Ay2jyRlXDkeU7tccde8DxS
# no_refine_4365.pth
gdown.download("https://drive.google.com/file/d/1l63AI9BsNovpfTAbfAkySo9X2MOWgYZH/view?usp=share_link", "no_refine_4365.pth", quiet=False)

# refine_4365.pth
gdown.download("https://drive.google.com/file/d/1aDLu0SB9JnPYZOOzQsJMV9zEIHg2Uro7/view?usp=share_link", "refine_4365.pth", quiet=False)

# Download YOLOv3 and HRNet pretrained models
# https://drive.google.com/drive/folders/1_ENAMOsPM7FXmdYRbkwbFHgzQq_B_NQA
# pose_hrnet_w48_384x288.pth
gdown.download("https://drive.google.com/file/d/1CpyZiUIUlEjiql4rILwdBT4666S72Oq4/view?usp=share_link", "pose_hrnet_w48_384x288.pth", quiet=False)

# yolov3.weights
gdown.download("https://drive.google.com/file/d/1gWZl1VrlLZKBf0Pfkj4hKiFxe8sHP-1C/view?usp=share_link", "yolov3.weights", quiet=False)

Ctrl+D
# Pretrained model
mkdir ./checkpoint/pretrained
mv no_refine_4365.pth ./checkpoint/pretrained/
mv refine_4365.pth ./checkpoint/pretrained/

# YOLOv3 and HRNet pretrained models
mv pose_hrnet_w48_384x288.pth ./demo/lib/checkpoint/
mv yolov3.weights ./demo/lib/checkpoint/
# Demo
MPLBACKEND=Agg python demo/vis.py --video sample_video.mp4

StridedTransformer-Pose3D Test NVIDIA Jetson Xavier NX Part 1

StridedTransformer-Pose3D Test NVIDIA Jetson Xavier NX Part 2

StridedTransformer-Pose3D Test NVIDIA Jetson Xavier NX Part 3



● RuntimeWarning: More than 20 figures have been opened.

Generating 3D pose...
  8%|███▎                                      | 20/255 [00:19<03:35,  1.09it/s]
/home/jetson/.local/lib/python3.8/site-packages/matplotlib/pyplot.py:530: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).

 plt.close()行を plt.savefig(xxxx)行の下に追加する。
plt.savefig(xxxx)
plt.close()


● UserWarning: Failed to load image Python extension:

pip install torchvision

python -c "import torchvision; print (torchvision.__version__)"
# /home/jetson/.local/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
#   warn(f"Failed to load image Python extension: {e}")
# 0.14.1

$ MPLBACKEND=Agg python demo/vis.py --video sample_video.mp4
/home/jetson/.local/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
  warn(f"Failed to load image Python extension: {e}")

● torchvision/io/image.py
try:
    _load_library("image")
except (ImportError, OSError) as e:
    warn(f"Failed to load image Python extension: {e}")

無視しても上のサンプルは動いた

 Gitからビルドしても同じ。

# PyTorch 1.13.0 = torchvision 0.14.0
# Build and Install torchvision from Git

# fatal error: libavcodec/avcodec.h: No such file or directory
sudo apt-get -y install libavcodec-dev
sudo apt-get -y install libavformat-dev

# fatal error: libswscale/swscale.h: No such file or directory
sudo apt-get -y install libswscale-dev

sudo apt-get -y install libjpeg-dev zlib1g-dev

cd
git clone --branch v0.14.0 https://github.com/pytorch/vision torchvision --depth 1
cd torchvision
export BUILD_VERSION=0.14.0
pip install --user setuptools
python setup.py install --user

# Gitからビルドしても Failed to load image Python extensionが出る
# しかも、install --userとしているので現在のディレクトリ以外では動作しない
# UserWarning: You are importing torchvision within its own root folder (/home/jetson/torchvision).
$ python -c "import torchvision; print (torchvision.__version__)"
/home/jetson/torchvision/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
  warn(f"Failed to load image Python extension: {e}")
/home/jetson/torchvision/torchvision/__init__.py:23: UserWarning: You are importing torchvision within its own root folder (/home/jetson/torchvision). This is not expected to work and may give errors. Please exit the torchvision project source and relaunch your python interpreter.
  warnings.warn(message.format(os.getcwd()))
0.14.0

# This approach is to manually rename 'image.pyd' in torchvision package folder (for example, the path is  'D:\conda\envs\py38\Lib\site-packages\torchvision' in my computer) to 'image.py'.

>>> import torch
>>> print(torch.__file__)
/home/jetson/.local/lib/python3.8/site-packages/torch/__init__.py
>>> import torchvision
/home/jetson/torchvision/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
  warn(f"Failed to load image Python extension: {e}")
/home/jetson/torchvision/torchvision/__init__.py:23: UserWarning: You are importing torchvision within its own root folder (/home/jetson/torchvision). This is not expected to work and may give errors. Please exit the torchvision project source and relaunch your python interpreter.
  warnings.warn(message.format(os.getcwd()))
>>> print(torchvision.__file__)
/home/jetson/torchvision/torchvision/__init__.py
>>> print(torch.cuda.is_available())
True

python -c "import site; print (site.getsitepackages())"
# ['/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']


● scikit_image.libs cannot allocate memory in static TLS block

ImportError: /home/jetson/.local/lib/python3.8/site-packages/skimage/_shared/../../scikit_image.libs/libgomp-d22c30c5.so.1.0.0: cannot allocate memory in static TLS block
It seems that scikit-image has not been built correctly.

Your install of scikit-image appears to be broken.
Try re-installing the package following the instructions at:
https://scikit-image.org/docs/stable/install.html


# Install scikit-image
python -m pip install -U scikit-image

# 再インストールしても解決しない
# 下記で解決した
export LD_PRELOAD=/home/jetson/.local/lib/python3.8/site-packages/skimage/_shared/../../scikit_image.libs/libgomp-d22c30c5.so.1.0.0


● https://github.com/Vegetebird/MHFormer

 動かない。動かせない。

cd
git clone https://github.com/Vegetebird/MHFormer --depth 1
cd MHFormer

pip install -r requirements.txt
# Download pretrained model
python

import gdown

# Download pretrained model
# https://drive.google.com/drive/folders/1UWuaJ_nE19x2aM-Th221UpdhRPSCFwZa
# 351 model_4294.pth
gdown.download("https://drive.google.com/file/d/1kaznEDkcElFT2s_NmLDnJESvNa2RNplJ/view?usp=share_link", "model_4294.pth", quiet=False)

# 243 model_4317.pth
gdown.download("https://drive.google.com/file/d/1cV3vYx7uCFMu4D5NYvKqfMtL6OzQXTMA/view?usp=share_link", "model_4317.pth", quiet=False)

# Download YOLOv3 and HRNet pretrained models
# https://drive.google.com/drive/folders/1_ENAMOsPM7FXmdYRbkwbFHgzQq_B_NQA
# pose_hrnet_w48_384x288.pth
gdown.download("https://drive.google.com/file/d/1CpyZiUIUlEjiql4rILwdBT4666S72Oq4/view?usp=share_link", "pose_hrnet_w48_384x288.pth", quiet=False)

# yolov3.weights
gdown.download("https://drive.google.com/file/d/1gWZl1VrlLZKBf0Pfkj4hKiFxe8sHP-1C/view?usp=share_link", "yolov3.weights", quiet=False)

Ctrl+D
# Pretrained model
mkdir ./checkpoint/pretrained/351
mv model_4294.pth ./checkpoint/pretrained/351/

mkdir ./checkpoint/pretrained/243
mv model_4317.pth ./checkpoint/pretrained/243/

# YOLOv3 and HRNet pretrained models
mv pose_hrnet_w48_384x288.pth ./demo/lib/checkpoint/
mv yolov3.weights ./demo/lib/checkpoint/
# Demo
MPLBACKEND=Agg python demo/vis.py --video sample_video.mp4

Generating 2D pose...
Traceback (most recent call last):
  File "demo/vis.py", line 277, in <module>
    get_pose2D(video_path, output_dir)
  File "demo/vis.py", line 90, in get_pose2D
    keypoints, scores = hrnet_pose(video_path, det_dim=416, num_peroson=1, gen_output=True)
  File "/home/jetson/MHFormer/demo/lib/hrnet/gen_kpts.py", line 95, in gen_video_kpts
    human_model = yolo_model(inp_dim=det_dim)
  File "/home/jetson/MHFormer/demo/lib/yolov3/human_detector.py", line 88, in load_model
    model.load_weights(args.weight_file)
  File "/home/jetson/MHFormer/demo/lib/yolov3/darknet.py", line 432, in load_weights
    conv_weights = conv_weights.view_as(conv.weight.data)
RuntimeError: shape '[64, 32, 3, 3]' is invalid for input of size 16393

# print(conv_weights.shape)
torch.Size([864])
torch.Size([16393])



Tags: [Raspberry Pi], [電子工作], [ディープラーニング]



[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2022 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/nvidia_jetson_install_strided_transformer_pose_3d/