【问题标题】:How to fix ' ModuleNotFoundError: No module named 'tensorflow.python.keras' importing ImagePrediction?如何修复'ModuleNotFoundError:没有名为'tensorflow.python.keras'的模块导入ImagePrediction?
【发布时间】:2019-05-30 05:59:22
【问题描述】:

我想运行 tensorflow 进行图像识别。我已经按照它的所有步骤进行操作,并且 keras 和 tensorflow 都安装在我的计算机上。 这篇文章中的步骤:https://github.com/OlafenwaMoses/ImageAI/ 但是当我尝试时: 从 imageai.Prediction 导入 ImagePrediction

我不断收到错误消息: 从 tensorflow.python.keras.preprocessing 导入图像 ModuleNotFoundError:没有名为“tensorflow.python.keras”的模块

我认为错误来自我安装的“tensorflow”。当我尝试该方法时: pip3 install --upgrade tensorflow 我得到了错误: 找不到满足要求 tensorflow 的版本(来自版本:) 没有找到 tensorflow 的匹配分布

所以我改用: python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

我从这个帖子中得到它:TensorFlow not found using pip

我的猜测是第一个错误将我推到第二个错误,但我不知道如何修复它们中的任何一个。

有什么建议吗?

我的代码直到问题是:

导入张量流

从 imageai.Prediction 导入 ImagePrediction

【问题讨论】:

  • 那个版本的TensorFlow没有Keras,太旧了,至少要安装TensorFlow 1.0
  • 你能不能试试pip3 install tensorflow==2.1,如果安装成功再试试“import tensorflow as tf”。然后将图像导入为“从 tensorflow.keras.preprocessing 导入图像:”。一个建议是请不要使用“from tensorflow.python.*”,因为它是 tensorflow 私有的,可能会更改或影响其他导入的模块。

标签: python tensorflow keras


【解决方案1】:

确保您拥有最新版本的 tensorflow (2.0)

import tensorflow as tf
print(tf.__version__)

from tensorflow.keras.preprocessessing.text import Tokenizer

【讨论】:

    【解决方案2】:

    而不是 “从 tensorflow.python.keras.preprocessing 导入图像” 写 "从 keras.preprocessing 导入图像"

    并对所有 Keras 调用执行相同的操作。

    【讨论】:

    • tensorflow 和 tensorflow.keras 并不完全相同
    猜你喜欢
    • 2019-12-17
    • 2019-10-06
    • 2019-09-18
    • 2019-07-10
    • 2021-07-03
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多