如何从目录外部运行tf_pose_estimation?

问题描述

我按照this文章在Mac上使用Tensorflow 2安装tf_pose_estimation。当我从“ tf_pose_estimation”目录中运行“ run_webcam.py”文件时,它工作正常。

>>> cd tf_pose_estimation 
>>> python3
Python 3.8.2 (v3.8.2:7b3ab5921f,Feb 24 2020,17:52:18) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help","copyright","credits" or "license" for more information.
>>> import run_webcam
>>> 

但是,当我尝试从'tf_pose_estimation'目录之外运行它时,出现以下错误

cd ..
python3
Python 3.8.2 (v3.8.2:7b3ab5921f,17:52:18)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help","credits" or "license" for more information.
>>> from tf_pose_estimation import run_webcam
Traceback (most recent call last):
File "<stdin>",line 1,in <module>
File "/Users/username/tf_pose_estimation/run_webcam.py",line 8,in <module>
from tf_pose.estimator import TfPoseEstimator
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tf_pose-0.1.1-py3.8-macosx-10.9-x86_64.egg/tf_pose/__init__.py",line 5,in <module>
from tf_pose.runner import infer,Estimator,get_estimator
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tf_pose-0.1.1-py3.8-macosx-10.9-x86_64.egg/tf_pose/runner.py",in <module>
from tf_pose import eval
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tf_pose-0.1.1-py3.8-macosx-10.9-x86_64.egg/tf_pose/eval.py",line 13,in <module>
from tf_pose.estimator import TfPoseEstimator
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tf_pose-0.1.1-py3.8-macosx-10.9-x86_64.egg/tf_pose/estimator.py",line 14,in <module>
import tensorflow.contrib.tensorrt as trt
ModuleNotFoundError: No module named 'tensorflow.contrib'
>>>

为什么以及如何解决?它显示安装TF2时尝试导入TF1函数错误。但是我上面链接文章恰好是用TF2安装它,并且在该目录中运行Python时它确实起作用。因此,我不明白为什么从其主目录外部运行它时会发生这种情况。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)