Tensorflow+OpenPose

系统 win10

cuda和cudnn的教程网上一堆,自己装好

本教程的cuda版本为

python版本3.5.2 tf版本1.7.1

这里上一个作者的环境搭建视频

https://www.youtube.com/watch?v=nUjGLjOmF7o

cmd输入python,再输入import tensorflow as tf,没报错的话,恭喜你,可以开始本教程了。


先上tensorflow版本openpose的地址

https://github.com/ildoonet/tf-pose-estimation

下载解压到任意路径下,建议路径不要太长,我的直接放在D盘

cmd定位到你的tf-pose-estimation-master文件夹

运行

pip install -r requirements.txt

requirements.txt文件内容如下

运行这个txt需要安装git,之前安装过的可以跳过这一节


https://git-scm.com/downloads/

点击显示屏里的连接下载

直接打开exe,一路next

安装成功后会出现桌面快捷方式,或者鼠标右击桌面

打开git bash,输入git,至此git安装完成,回到前面说的pip install -r requirements.txt

等待安装完成后运行py。好的,一堆报错大概有两个报错

ImportError: No module named '_pafprocess'

NameError: name 'ModuleNotFoundError' is not defined

这也是最坑的地方。找了很多issues才找到答案

我们看看官方是怎么说的

没错,我们还要用swig编译一次

ok,先来下swig,同样之前下过的可以跳过这一节


我的swig版本是swigwin-3.0.12,下载地址是http://www.swig.org/download.html

解压zip,比如:D:\backupsoftware

添加环境变量到path, 比如: D:\backupsoftware\swigwin-3.0.12

在命令行执行: swig --help,不报错说明安装成功了。


下面开始swig代码,进入tf-pose-estimation-master文件夹下,cmd定位到D:\tf-pose-estimation\tf_pose\pafprocess

运行

swig -python -c++ pafprocess.i && python setup.py build_ext --inplace

如果不报错,你的文件夹内容应该是这样的

如果报错了,恭喜你,又中奖了,而且我猜你的错误应该是这个

Unable to find vcvarsall.bat

首先找到你的vcvarsall.bat所在路径。也就是这个文件

此文件一般位于vs安装路径下,我的路径:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build

接着说一个我们需要让python找到这个文件,这里只介绍我成功的方法,如果不行,百度百度百度

首先找到_msvccompiler.py文件,我的路径是C:\Users\work-25\Anaconda3\envs\tensorflow-gpu\Lib\distutils

你们在自己的python文件下面找找。打开这个文件,找到

def _find_vcvarsall(plat_spec):

没修改前,这个方法是这样的

def _find_vcvarsall(plat_spec):
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    with key:
        best_version = 0
        best_dir = None
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
        if not best_version:
            log.debug("No suitable Visual C++ version found")
            return None, None

        vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
        if not os.path.isfile(vcvarsall):
            log.debug("%s cannot be found", vcvarsall)
            return None, None

        vcruntime = None
        vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
        if vcruntime_spec:
            vcruntime = os.path.join(best_dir,
                vcruntime_spec.format(best_version))
            if not os.path.isfile(vcruntime):
                log.debug("%s cannot be found", vcruntime)
                vcruntime = None

        return vcvarsall, vcruntime

修改后是这样的

def _find_vcvarsall(plat_spec):
        best_dir = r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build'
        best_version = 17
        vcruntime = None
        vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
        if vcruntime_spec:
            vcruntime = os.path.join(best_dir,
                vcruntime_spec.format(best_version))
            if not os.path.isfile(vcruntime):
                log.debug("%s cannot be found", vcruntime)
                vcruntime = None
        print(vcruntime)
        return r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat', vcruntime

再次回到pafprocess文件夹运行

swig -python -c++ pafprocess.i && python setup.py build_ext --inplace

不报错就成功了,到这里你就可以成功使用tf-openpose了

定位到D:\tf-pose-estimation,运行

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

来张骚猪和吴秀波(孙狗)的斗舞

fps有点低,我电脑配置垃圾,总体来说效果还算不错

  • 5
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 52
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 52
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值