分類:動(dòng)作捕捉
github地址:https://github.com/Daniil-Osokin/lightweight-human-pose-estimation-3d-demo.pytorch
所需環(huán)境:
Windows10,conda 4.13.0;
conda環(huán)境配置
conda create -n lwmhpe3d python=3.8
conda activate lwmhpe3d
D:
cd D:\WLm_Project\MotionCatch\lwmhpe3d
安裝Pytorch全家桶
pip install "torch-1.13.1+cu116-cp38-cp38-win_amd64.whl"# 離線安裝 需要預(yù)先下載
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116
cd lwmhpe3d
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
安裝TensorRT(可選)
python -m pip install nvidia-pyindex
# nvidia官網(wǎng)下載TensorRT-8.6.1.6.Windows10.x86_64.cuda-11.8.zip:https://developer.nvidia.com/nvidia-tensorrt-8x-download
# 下載完成后 移動(dòng)并解壓縮
cd D:\WLm_Project\MotionCatch\lwmhpe3d\TensorRT-8.6.1.6.Windows10.x86_64.cuda-11.8\TensorRT-8.6.1.6\python
# 因?yàn)槭莗ython3.8環(huán)境 要安裝這個(gè)
pip install tensorrt-8.6.1-cp38-none-win_amd64.whl
安裝成功
將這tensorRT的三個(gè)文件夾復(fù)制到CUDA下( 記得復(fù)制之前CUDA的原始三個(gè)文件夾做好副本 注意路徑)
安裝torch2trt(可選)
cd D:\WLm_Project\MotionCatch\lwmhpe3d
git clone https://github.com/NVIDIA-AI-IOT/torch2trt
cd torch2trt
pip3 install packaging -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -e .
模型轉(zhuǎn)換為TensorRT兼容格式(可選)
# 轉(zhuǎn)換human-pose-estimation-3d.pth為human-pose-estimation-3d-trt.pth
python scripts/convert_to_trt.py --checkpoint-path human-pose-estimation-3d.pth
很奇怪 我的convert_to_trt.py沒法找到上級(jí)目錄中models與modules的文件
簡(jiǎn)單粗暴的解決辦法是: 把lwmhpe3d\lwmhpe3d\models和lwmhpe3d\lwmhpe3d\modules的所有文件都復(fù)制到lwmhpe3d\lwmhpe3d\scripts下
并修改convert_to_trt.py ; with_mobilenet.py腳本 使python腳本變?yōu)橥?jí)文件夾尋址:
運(yùn)行指令
# 構(gòu)建pose_extractor模塊:
cd D:\WLm_Project\MotionCatch\lwmhpe3d\lwmhpe3d
# python setup.py build_ext
# 將構(gòu)建文件夾添加到PYTHONPATH:
# export PYTHONPATH=pose_extractor/build/:$PYTHONPATH
# 安裝完依賴項(xiàng)后可以直接運(yùn)行 無需編譯
# 使用GPU
python demo.py --model human-pose-estimation-3d.pth --video 0 --device GPU
# 使用tensorRT(可選)
python demo.py --model human-pose-estimation-3d-trt.pth --use-tensorrt --video 0
使用tensorRT運(yùn)行指令報(bào)錯(cuò):
[09/06/2023-09:32:05] [TRT] [E] 3: [executionContext.cpp::nvinfer1::rt::ExecutionContext::validateInputBindings::2083] Error Code 3: API Usage Error (Parameter check failed at: executionContext.cpp::nvinfer1::rt::ExecutionContext::validateInputBindings::2083, condition: profileMinDims.d[i] <= dimensions.d[i]. Supplied binding dimension [1,3,256,336] for bindings[0] exceed min ~ max range at index 3, maximum dimension in profile is 448, minimum dimension in profile is 448, but supplied dimension is 336.
這個(gè)問題 作者在github上有說明
TensorRT does not support dynamic network input size reshape. Make sure you have set proper network input height, width with --height and --width options during conversion (if not, there will be no detections). Default values work for a usual video with 16:9 aspect ratio (1280x720, 1920x1080). You can check the network input size with print(scaled_img.shape) in the demo.py
TensorRT 不支持動(dòng)態(tài)網(wǎng)絡(luò)輸入大小重塑。確保您在轉(zhuǎn)換過程中設(shè)置了正確的網(wǎng)絡(luò)輸入高度、寬度和–height選項(xiàng)–width(如果沒有,將不會(huì)進(jìn)行檢測(cè))。默認(rèn)值適用于寬高比為 16:9 的普通視頻(1280x720、1920x1080)。print(scaled_img.shape)您可以在 demo.py 中檢查網(wǎng)絡(luò)輸入大小
可以在demo.py中加入打印語句
運(yùn)行GPU推理時(shí)果然顯示
所以需要手動(dòng)更改這個(gè)值 在convert_to_trt.py的位置如下:將448改成336即可
再次運(yùn)行使用TensorRT推理指令即可成功!
運(yùn)行結(jié)果
按esc
退出
GPU運(yùn)行
TensorRT加速
TensorRT的FPS提升了一倍 接近60幀 然而GPU只有30幀 雖然視覺上差不了太多
conda list
# packages in environment at D:\Anaconda3\envs\lwmhpe3d:
#
# Name Version Build Channel
ca-certificates 2023.05.30 haa95532_0
certifi 2023.7.22 pypi_0 pypi
charset-normalizer 3.2.0 pypi_0 pypi
idna 3.4 pypi_0 pypi
libffi 3.4.4 hd77b12b_0
numpy 1.24.4 pypi_0 pypi
nvidia-pyindex 1.0.9 pypi_0 pypi
onnx 1.14.1 pypi_0 pypi
opencv-python 4.8.0.76 pypi_0 pypi
openssl 3.0.10 h2bbff1b_2
packaging 23.1 pypi_0 pypi
pillow 10.0.0 pypi_0 pypi
pip 23.2.1 py38haa95532_0
protobuf 4.24.2 pypi_0 pypi
python 3.8.17 h1aa4202_0
requests 2.31.0 pypi_0 pypi
setuptools 68.0.0 py38haa95532_0
sqlite 3.41.2 h2bbff1b_0
tensorrt 8.6.1 pypi_0 pypi
torch 1.13.1+cu116 pypi_0 pypi
torch2trt 0.4.0 dev_0 <develop>
torchaudio 0.13.1+cu116 pypi_0 pypi
torchvision 0.14.1+cu116 pypi_0 pypi
typing-extensions 4.7.1 pypi_0 pypi
urllib3 2.0.4 pypi_0 pypi
vc 14.2 h21ff451_1
vs2015_runtime 14.27.29016 h5e58377_2
wheel 0.38.4 py38haa95532_0
以下是執(zhí)行setup失敗后的嘗試 實(shí)際上不需要編譯setup也可執(zhí)行demo 只是實(shí)時(shí)性不好(但是我需要的是算法 讀者不用看以下部分 這是我自己的記錄)
官網(wǎng)要求:
Python 3.5(或更高版本 )–>環(huán)境是3.8
CMake 3.10(或更高版本 )–>環(huán)境是3.27
C++ 編譯器(g++ 或 MSVC ) -->環(huán)境是C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
OpenCV 4.0(或更高版本)–>環(huán)境是4.8.0
Opencv4.8.0配置環(huán)境變量
需要提前編譯好并配置環(huán)境變量
https://github.com/opencv/opencv
無法解決的問題:
Cmake3.27配置環(huán)境變量
直接下載壓縮包 將bin下的exe存在的路徑按下圖添加到path環(huán)境變量
https://cmake.org
cmake --version# 需要先配置環(huán)境變量
文章來源:http://www.zghlxwxcb.cn/news/detail-695820.html
參考鏈接
1.windows下cmake的安裝與環(huán)境變量配置教程
2.Windows下Visual Studio 編譯OpenCV詳細(xì)教程(win10+vs2017+opencv4.5.2)(OpenCV最新版)(特別適合無法科學(xué)上網(wǎng)的童鞋們)
3.OpenCV 文件下載文章來源地址http://www.zghlxwxcb.cn/news/detail-695820.html
到了這里,關(guān)于論文復(fù)現(xiàn)--lightweight-human-pose-estimation-3d-demo.pytorch(單視角多人3D實(shí)時(shí)動(dòng)作捕捉DEMO)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!