tf-pose-estimation-安装记录(Tensorflow实现)


1.前提是已经安装过TensorFlow-gpu版本了

  TensorFlow-gpu版本安装教程参考https://blog.csdn.net/weixin_41320468/article/details/104511105?utm_medium=distribute.pc_relevant.none-task-blog-utm_term-2&spm=1001.2101.3001.4242

1).先安装anaconda3

2).创建一个tensorflow-gpu的环境:conda create -n tensorflow_gpuenv

3).下载并安装cuda10,添加环境变量

4).下载并解压cudnn7.4,复制那三个文件到cuda下面

5).激活环境:conda activate tensorflow_gpuenv

6).在该环境下安装tensoflow-gpu1.14(使用清华镜像): pip install --ignore-installed --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.14.0

7).检测是否成功:
activate tensorflow_gpuenv
python #进入python
#下面测试tensorflow-gpu是否安装成功
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

2.下载tf-pose-estimation源码

下载地址:https://github.com/ildoonet/tf-pose-estimation

 

 3.requirements文件里面有所需要的模块

  1)在这里,先安装git

   conda activate tensorflow_gpuenv//进入TensorFlow环境

   conda install git//安装git

      E:

    cd E:\tf-pose-estimation-master\tf-pose-estimation-master//进入到下载的tf-openpose-estimation-master文件目录

      pip install -r requirements.txt

   

  

         

 

   如上所示,安装成功。

4.安装opencv

  首先要看一下自己电脑支持的版本

  python

  import pip._internal

  print(pip._internal.pep425tags.get_supported())

  如下所示:

  

 

   则去https://www.lfd.uci.edu/~gohlke/pythonlibs/下载下面对应的文件,64位电脑就win_amd64,32位电脑就win32.

 

  下载放置目录,等待安装

  

 

 

   pip install E:\tf-pose-estimation-master\tf-pose-estimation-master\opencv_python-4.4.0-cp37-cp37m-win_amd64.whl

  如下所示便表示安装成功

  

 

 5.Build c++ library

  先要下载swig,这一步会比较麻烦。目前到现在为止我都不知道咋安装成功的.

  1.swig下载地址

  http://prdownloads.sourceforge.net/swig/swigwin-3.0.12.zip

  2.解压放置目录

  E:\swigwin-3.0.12或者C:\swigwin-3.0.12

      

  3.添加环境变量

  下面这两个是,分别是在用户变量中和系统变量中创建的

    

       

  下面这两个是在用户变量和系统变量的path中添加的。我只知道,我的是两个都弄了才成功的,网上是说进行下面的一个就行,如添加C:\swigwin-3.0.12

     

 

   

 

 经过一番骚操作,竟然成功了。过程如下:

在进入E:\tf-pose-estimation-master\tf-pose-estimation-master\tf_pose\pafprocess下执行如下代码

swig -python -c++ pafprocess.i && python setup.py build_ext --inplace(我这个时候好像是没有激活tensorflow环境)

(这里是因为我这个base的环境本身就包含了很多包的,可以通过conda list查看当前环境已经安装的东西,缺啥或者需要啥就装啥。)

      

 

      

 

 如上,则表示成功。反之,如果出现下面结果,那就是环境变量有问题。

      

 

 6.调用摄像头或者图片检测

  完成5之后就算大工搞成了,但是还差一点。

  //调用摄像头显示

  python run_webcam.py --model=mobilenet_thin --resize=432x368 --camera=0

  //调用图片

  python run.py --model=mobilenet_thin --resize=432x368 --image=./images/p1.jpg

  如果能成功显示最好,但是也有可能出现下面问题:

  

 

     出现的原因...算了我太懒了。

  直接简单粗暴解决-.-找到对应错误文件

  

 

 把这一行注释掉

 

       

 如果需要调用本地视频,则需要修改run_video.py文件,修改后代码如下

import argparse
import logging
import time

import cv2
import numpy as np

from tf_pose import common
from tf_pose.estimator import TfPoseEstimator
from tf_pose.networks import get_graph_path, model_wh

logger = logging.getLogger('TfPoseEstimator-Video')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

fps_time = 0


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='tf-pose-estimation Video')
parser.add_argument('--video', type=str, default='./videos/appledancing.mp4') #改为自己的输入视频
parser.add_argument('--resolution', type=str, default='432x368', help='network input resolution. default=432x368')
parser.add_argument('--model', type=str, default='mobilenet_thin', help='cmu / mobilenet_thin / mobilenet_v2_large / mobilenet_v2_small')
parser.add_argument('--resize-out-ratio', type=float, default=4.0,help='if provided, resize heatmaps before they are post-processed. default=1.0')
parser.add_argument('--show-process', type=bool, default=False,help='for debug purpose, if enabled, speed for inference is dropped.')
parser.add_argument('--showBG', type=bool, default=True, help='False to show skeleton only.')
args = parser.parse_args()

logger.debug('initialization %s : %s' % (args.model, get_graph_path(args.model)))
w, h = model_wh(args.resolution)
e = TfPoseEstimator(get_graph_path(args.model), target_size=(w, h))
cap = cv2.VideoCapture(args.video)

ret_val, image = cap.read()
video_size = (image.shape[1],image.shape[0])
fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', '2')
#video_size = (2560,1920)
outVideo = cv2.VideoWriter('save.avi', fourcc, 30, video_size)#这个参数30原本是10的,默认是10FPS保存文件的,可以根据实际的FPS大小,调整一下,比如我台式机是30FPS,那么就调整成30.
#filename = '/home/yasin/save.avi' #更改为自己的保存路径
if cap.isOpened() is False:
print("Error opening video stream or file")
while cap.isOpened():
ret_val, image = cap.read()

if not ret_val:
break
logger.debug('image process+')
#image = common.read_imgfile(args.image, None, None)
humans = e.inference(image, resize_to_default=(w > 0 and h > 0), upsample_size=args.resize_out_ratio)

logger.debug('postprocess+')
image = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)
logger.debug('show+')
# image_res = cv2.resize(image,(640,480))
cv2.putText(image, "FPS: %f" % (1.0 / (time.time() - fps_time)), (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5,(0, 255, 0), 2)
cv2.imshow('tf-pose-estimation result', image)
fps_time = time.time()
outVideo.write(image)
# video_write = cv2.VideoWriter(filename, fourcc, 10, video_size)
# video_write.write(image)

if cv2.waitKey(1) == 27:
break
logger.debug('finished+')
cap.release()
outVideo.release()
cv2.destroyAllWindows()
''' while cap.isOpened():
ret_val, image = cap.read()

humans = e.inference(image,resize_to_default=(w > 0 and h > 0))
if not args.showBG:
image = np.zeros(image.shape)
image = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)

cv2.putText(image, "FPS: %f" % (1.0 / (time.time() - fps_time)), (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imshow('tf-pose-estimation result', image)
fps_time = time.time()
if cv2.waitKey(1) == 27:
break

cv2.destroyAllWindows()
logger.debug('finished+')
'''

至此,就能完美运行了,打完收工ovo。

 

运行python代码可能遇到的错误

TabError: inconsistent use of tabs and spaces in indentation

这是因为没有正确使用Tab和Space的问题。

 

  

 

  

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM