【问题标题】:I found ModuleNotFoundError: No module named 'tensorflow.contrib'我发现 ModuleNotFoundError: No module named 'tensorflow.contrib'
【发布时间】:2020-04-03 03:22:59
【问题描述】:

我尝试在 CMD 上运行 python。 我在我的 python 文件中导入 tensorflow.contrib。

import tensorflow.contrib.tensorrt as trt

使用此命令在 anaconda 上运行时。

python run_webcam.py --camera yoga.mp4

显示错误:

  File "run_webcam.py", line 8, in <module>
    from tf_pose.estimator import TfPoseEstimator
  File "D:\work\pose estimation\tf-pose-estimation\tf_pose\__init__.py", line 5, in <module>
    from tf_pose.runner import infer, Estimator, get_estimator
  File "D:\work\pose estimation\tf-pose-estimation\tf_pose\runner.py", line 8, in <module>
    from tf_pose import eval
  File "D:\work\pose estimation\tf-pose-estimation\tf_pose\eval.py", line 13, in <module>
    from tf_pose.estimator import TfPoseEstimator
  File "D:\work\pose estimation\tf-pose-estimation\tf_pose\estimator.py", line 14, in <module>
    import tensorflow.contrib.tensorrt as trt
ModuleNotFoundError: No module named 'tensorflow.contrib'

我安装了

pip install tensorflow

并更改tensorflow的版本(尝试卸载并安装多个版本)

pip uninstall tensorflow
pip install tensorflow==...

但显示相同的错误

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    尝试替换以下内容

    import tensorflow.contrib.tensorrt as trt(用于≤TensorFlow 1.13.1)

    from tensorflow.python.compiler.tensorrt import trt(TensorFlow ≥ 1.14.1)

    感谢GitHub

    【讨论】:

    • 我的 TensorFlow 版本是 tensorflow 2.2.0rc2,我是这样导入的。我仍然出错。当我尝试 ``` from tensorflow.python.compiler.tensorrt import trt ``` 并更改版本。它的错误也一样。 @incarnadine
    • 在 1.15.0 版本中使用 from tensorflow.python.compiler.tensorrt import trt 时出现此错误“ImportError: cannot import name 'trt_convert' from 'tensorflow.python.compile r.tensorrt”
    猜你喜欢
    • 1970-01-01
    • 2022-12-27
    • 2022-12-27
    • 2022-12-19
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 2022-10-17
    相关资源
    最近更新 更多