首页 > 解决方案 > 我发现 ModuleNotFoundError: No module named 'tensorflow.contrib'

问题描述

我尝试在 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==...

但显示相同的错误

标签: pythontensorflow

解决方案


尝试替换以下

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

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

归功于GitHub


推荐阅读