tfpose与openpose区别_人体姿态识别--Openpose+Tensorflow
目的復現代碼
完成視頻中的人體姿態識別
復現過程
視頻來源:https://www.youtube.com/watch?v=cMhWNGBW1Xg?www.youtube.com
視頻動圖
檢測結果下載的畫質本來就不高,再加上兩次錄屏,畫質比較渣。
首先確認工程所需要的依賴:python3
tensorflow 1.4.1+
opencv3, protobuf, python3-tk
slidingwindow
然后進行安裝:
$ git clone https://www.github.com/ildoonet/tf-pose-estimation
$ cd tf-pose-estimation
$ pip3 install -r requirements.txt
這里我的當前的環境中,pip對應的版本是python3,所以修改該命令為
pip install -r requirements.txt
遇到以下問題:
Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple/
Collecting git+https://github.com/ppwwyyxx/tensorpack.git
Cloning https://github.com/ppwwyyxx/tensorpack.git to /tmp/pip-req-build-d9276zkb
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-req-build-d9276zkb/setup.py", line 7, in
assert version > 30, "Tensorpack installation requires setuptools > 30"
AssertionError: Tensorpack installation requires setuptools > 30
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-d9276zkb/
根據提示,是因為setuptools版本太低,于是更新
pip install --ignore-installed --upgrade setuptools
后續又提示幾個依賴出現同樣的版本問題,可以用上面的命令逐一更新。
最后安裝成功顯示:
Successfully built tensorpack
Installing collected packages: tensorpack
Successfully installed tensorpack-0.9.4
然后編譯C++庫
$ cd tf_pose/pafprocess
$ swig -python -c++ pafprocess.i && python3 setup.py build_ext --inplace
輸出:
swig -python -c++ pafprocess.i && python setup.py build_ext --inplace
The program 'swig' can be found in the following packages:
* swig
* swig2.0
Try: sudo apt install
根據提示安裝swig
sudo apt install swig
再次運行
swig -python -c++ pafprocess.i && python setup.py build_ext –inplace
接著遇到了CUDA版本的問題
ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
因為之前在python27虛擬環境中使用cuda8,現在在python3中使用cuda10,所以需要更換cuda的路徑,這里可以參考:shellyfung:人體姿態識別--AlphaPose+TensorFlow?zhuanlan.zhihu.com
更換之后運行demo
python run.py --model=mobilenet_thin --resize=432x368 --image=./images/p1.jpg
輸出以下信息:
Status: CUDA driver version is insufficient for CUDA runtime version
這里需查看以下內容NVIDIA驅動
CUDA版本
tensorflow版本
這三者之間是有版本對應關系的,因為目前切換了cuda10,而對應的nvidia驅動版本過低,因此重新安裝NVIDIA驅動,這里大家可以參考網絡上的教程,卸載的方式和你安裝的方式最好是對應的。安裝完成之后,使用nvidia-smi查看安裝結果。
然后運行
python run.py --model=mobilenet_thin --resize=432x368 --image=./images/p1.jpg
可以在對應的路徑下查找輸出的結果。
檢測視頻
作者提供了一個攝像頭實時檢測的腳本
python run_webcam.py --model=mobilenet_thin --resize=432x368 --camera=0
因為我要檢測視頻,所以需要修改部分內容。
打開run_webcam.py,查看讀取攝像頭的代碼
作者是使用opencv讀取的攝像頭,而在opencv中,讀取攝像頭和讀取視頻使用的方法是一樣的,只不過需要修改傳入參數。首先在本地測試讀入視頻,代碼如下:
import cv2
import numpy as np
cap = cv2.VideoCapture("video.mp4")
while 1:
ret, frame = cap.read()
cv2.imshow("capture", frame)
if cv2.waitKey(100) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
可以成功讀取視頻,只不過使用的是cpu,畫面非常的卡頓。
接著修改腳本中的參數:
# parser.add_argument('--camera', type=int, default=0)
parser.add_argument('--camera', type=str, default='0x0')
然后在終端運行:
python run_webcam.py --model=mobilenet_thin --resize=432x368 --camera=video.mp4
只需要將—camera=后面的內容修改為視頻的名稱就可以,前提是視頻需要和腳本放在同一目錄下。
然后就可以看到輸出結果了,視頻截圖:
可以看到,在某些動作比較快的畫面下,檢測結果的丟幀還是存在的。
完整檢測后的視頻鏈接:https://youtu.be/zdIyKFJ4xzg?youtu.be
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的tfpose与openpose区别_人体姿态识别--Openpose+Tensorflow的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java学习(30):巩固练习
- 下一篇: SAP表维护自动带出对象属性