Python 属性错误:模块';tensorflow';没有属性';图像';

Python 属性错误:模块';tensorflow';没有属性';图像';,python,tensorflow,Python,Tensorflow,该代码昨天运行良好: import tensorflow as tf import cv2 augmentedImageLeftRight = tf.image.random_flip_left_right(srcImage) cv2.imshow('image', augmentedImageLeftRight) cv2.waitKey(0) cv2.destroyAllWindows() 今天我添加了这一行: augmentedRotation = tf.image.rot90(srcI

该代码昨天运行良好:

import tensorflow as tf
import cv2

augmentedImageLeftRight = tf.image.random_flip_left_right(srcImage)
cv2.imshow('image', augmentedImageLeftRight)
cv2.waitKey(0)
cv2.destroyAllWindows()
今天我添加了这一行:

augmentedRotation = tf.image.rot90(srcImage, k=2)
添加此代码后,我收到以下错误消息:

augmentedImageLeftRight = tf.image.random_flip_left_right(srcImage)
AttributeError: module 'tensorflow' has no attribute 'image'
Traceback (most recent call last):
  File "C:/Users/Maximal/Documents/Python/PyCharm/TrafficSignClassification/run/predictValidationData.py", line 1, in <module>
    from model.trafficSignsClassification import Model
  File "C:\Users\Maximal\Documents\Python\PyCharm\TrafficSignClassification\model\trafficSignsClassification.py", line 3, in <module>
    from tensorflow import keras
ImportError: cannot import name 'keras'
事实上,我没有改变其他任何事情。即使我删除了我添加的行,它仍然不起作用

编辑: Sh*t。我的密码全坏了。我什么也没做,只是开始PyCharm并添加一行。我刚刚意识到我不能再运行整个目录中的任何文件了。从TF或Keras导入内容时,每个文件都会给我一个错误。有这么多的错误信息,我不知道从哪里开始。我不能把它们都贴在这里。我只是把它推到GitHub的“测试”分支上。请有人看看。我一点也不明白现在发生了什么

编辑2: 如果运行“predictValidationData”,它只调用文件“trafficSignsClassification”中的run函数,则无法运行主文件。我会收到以下错误消息:

augmentedImageLeftRight = tf.image.random_flip_left_right(srcImage)
AttributeError: module 'tensorflow' has no attribute 'image'
Traceback (most recent call last):
  File "C:/Users/Maximal/Documents/Python/PyCharm/TrafficSignClassification/run/predictValidationData.py", line 1, in <module>
    from model.trafficSignsClassification import Model
  File "C:\Users\Maximal\Documents\Python\PyCharm\TrafficSignClassification\model\trafficSignsClassification.py", line 3, in <module>
    from tensorflow import keras
ImportError: cannot import name 'keras'
我试图实现这样的东西,但PyCharm突出显示了“random_uniform”(随机统一)一条弹出的消息,在init.py中提到了关于随机统一函数/声明的内容。我只是想好了,不管我不知道这是什么,所以我关闭了窗口并删除了随机统一部分。此后,整个项目中的每个TF导入都不再工作。不幸的是,我没有截屏窗口,也不知道确切的消息。

@jakub 我刚刚在PyCharm中创建了一个新项目,并尝试从tf导入一个模块。即使这样也不行。PyCharm以某种方式改变了模块tf


向我们显示整个错误消息,包括完整堆栈跟踪。检查tensorflow的版本。使用
pip列表
检查tensorflow是否仍然安装并且是最新的。您是否以某种方式修改了您的环境,例如安装/删除/更新了一些软件包?@Daniel这是一个愚蠢的想法,但您能试着重新安装tensorflow吗?我的一个想法是PyCharm实际上允许直接导航到lib源代码,您可能不小心删除/修改了其中的某些内容,这导致了TF中的错误。@RayanRal我刚刚重新安装了它,它又能工作了。PyCharm不知怎么搞砸了我的tf包。非常感谢您的快速修复!