本文共 3512 字,大约阅读时间需要 11 分钟。
首先介绍一下安装的环境:
Win 10
Python 3.6 CUDA 10.0 cuDNN 7.6.0安装参考
conda create -n tfpose python=3.6
创建一个新的conda环境,后用activate tfpose
激活环境。pip install -r requirements.txt
为了让速度快些,我加了清华镜像。 (1)如果遇到"module ‘pip’ had no attribute ‘main’(这个问题好像经常遇到)在这里我使用的方式是:在pip前加上python -m
(2)解决完上一个问题,我重新输入pip install -r requirements.txt
,又出现报错。 先解决Cython的问题,我们都知道,遇到“No module named xxx”的问题,直接pip install就行。 (3)后续如果还有报红,例如: 直接继续pip install 就行了,于是后续又安装了Matplotlib和Pillow。 (4)重新执行pip install -r requirements.txt
,这时出现了大片的报红。主要问题是Pycocotools安装出现问题,安装不成功是因为不支持windows系统,在网上查找了一些方法,找到了支持windows的文件: 具体的安装办法: 在cmd中cd到cocoapi-master\PythonAPI文件夹中,然后执行python setup.py build_ext install
(5)上述操作又报错: 没有rc.exe这个文件,所以: 先在C:\Program Files (x86)\Windows Kits\8.1\bin\x86中寻找到 rc.exe rcdll.dll 再复制到C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin下,执行代码,解决了。 最后再重新执行一次pip install -r requirements.txt
即可。pip install opencv_python‑4.1.2‑cp36‑cp36m‑win_amd64.whl
安装tensorflow,出现报错:
pip install grpcio==1.24.3就行。运行python run_webcam.py --model=mobilenet_thin_432*368 --camera=0
,报错:
再次执行:python run_webcam.py --model=mobilenet_thin_432*368 --camera=0
swig --help
如果没有error就是安装成功了。 (4)确保在虚拟环境tfpose下,cd到D:\tf-pose-estimation\tf_pose\pafprocess (根据自己的情况cd) 执行:swig -python -c++ pafprocess.i && python setup.py build_ext --inplace
不报错即可。如果报错,估计错误是: Unable to find vcvarsall.bat 参考文章。 很好,已经排除这么多问题了,我们继续。
回到D:\tf-pose-estimation 重新执行python run_webcam.py --model=mobilenet_thin_432*368 --camera=0
出现报错:No module named ‘matplotlib’ pip install即可。 再次重新运行python run_webcam.py --model=mobilenet_thin_432*368 --camera=0
python run_webcam.py --model=mobilenet_thin --resize=432x368 --camera=0
恭喜你,现在已经跑起来了!!能从摄像头看到自己吗?
python run.py --model=mobilenet_thin --resize=432x368 --image=./images/p1.jpg
出现报错:UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
解决方法:打开tf-pose-estimation中的run.py文件,将第56行import matplotlib.pyplot as plt
改为: import matplotlib matplotlib.use(‘TkAgg’)
import matplotlib.pyplot as plt 再次运行就成功了,能够看到python run_video.py --model=mobilenet_thin --resolution=432x368 --video=./etcs/dance.mp4
执行发现,舞者跳舞的时候,没有骨骼识别的痕迹。打开tf-pose-estimation中的run_video.py文件
解决办法: (1)添加一段代码parser.add_argument('--resize-out-ratio', type=float, default=4.0, help='if provided, resize heatmaps before they are post-processed. default=1.0')
具体添加位置下图第一块黄色区域。
(2)下方的while cap.isOpened()中humans = e.inference(image)改为humans = e.inference(image, resize_to_default=(w > 0 and h > 0), upsample_size=args.resize_out_ratio)
如下图第二块黄色区域 到此所有问题都解决了,基于tensorflow的openpose也跑起来了,是不是很开心呢?恭喜你!
参考: