ModuleNotFoundError: No module named 'keras.engine.topoloary ’ 问题的解决!
在调试从网上下载的代码时,习惯于用自己原来的tensorflow和keras环境进行调试,出现错误时,便从自身的tensorflow和keras版本是否兼容,安装过程是否正确,是否缺少什么文件之类…这些方面来考虑,经过多番重装,更换调试环境,发现这样的问题依然存在,本来已经打算放弃,临睡前,突然意识到,会不会是自己的环境和源代码的调试环境不匹配!!!**
果然,从程序报错源头,发现 tensorflow2.0.0、keras2.3.1(源程序的调试环境)与tensorflow1.7.0、keras2.1.6(现有的调试环境)在有些地方发生了变动,导致一直报错,并非是代码本身的问题,而是随着版本的升级,有些源文件名发生了改变**,所以问题很难找出来。
解决方法:
重新安装了keras 与 tensorflow,换成源程序需要的版本!
Pip uninstall XXX

ModuleNotFoundError: No module named ‘tensorflow’
在这里插入图片描述
斯坦福大学:Tensorflow最通俗易懂的入门教程「强烈推荐」
https://www.sohu.com/a/232428661_100127949

idea Error running ‘xxxx类’: Cannot start process, the working directory ‘E:\xxx\xxx’ does not exist
Edit Configurations… resnet50 script.path未配好

ModuleNotFoundError: No module named ‘keras‘解决方法
python -m pip install keras
Windows刚安装好Tensorflow以后运行
import tensorflow as tf
hello = tf.constant(‘hello world’)
sess = tf.Session()
print(sess.run(hello))
结果报错
AttributeError: module ‘tensorflow’ has no attribute ‘Session’
是因为在新的Tensorflow 2.0版本中已经移除了Session这一模块,改换运行代码
tf.compat.v1.Session()
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant(‘hello,tensorf’)
sess = tf.compat.v1.Session()
print(sess.run(hello))
结果:
‘hello,world’
即:
import tensorflow.compat.v1 as tf
hello = tf.constant(‘hello world’)
sess = tf.compat.v1.Session()
print(sess.run(hello))

win10 pycharm环境下tensorflow-gpu安装
https://blog.csdn.net/qq_35494379/article/details/105230052?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165257369316782350998094%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=165257369316782350998094&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-2-105230052-null-null.142v9control,157v4control&utm_term=pycharm%E5%AE%89%E8%A3%85tensorflow+gpu&spm=1018.2226.3001.4187

关于在pycharm中搭建tensorflow-gpu环境的详细安装过程记录
https://blog.csdn.net/eye123456789/article/details/110821977?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165257369316782350998094%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=165257369316782350998094&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-110821977-null-null.142v9control,157v4control&utm_term=pycharm%E5%AE%89%E8%A3%85tensorflow+gpu&spm=1018.2226.3001.4187

ImportError: cannot import name ‘_obtain_input_shape’ from ‘keras.applications.imagenet_utils’

原因
_obtain_input_shape换地方了
解决
from keras.applications.imagenet_utils import _obtain_input_shape
改成
from keras_applications.imagenet_utils import _obtain_input_shape
在这里插入图片描述
运行resnet34
AttributeError: module ‘tensorflow’ has no attribute ‘random_uniform’
解决办法:tf2.0中用tf.random.uniform代替了random_uniform

tensorflow 版本 不兼容产生的报错
https://blog.csdn.net/qq_53144843/article/details/

执行程序遇到报错:AttributeError: module ‘tensorflow’ has no attribute ‘xxx’ 解决办法
1.如果你导入Tensorflow模块的代码为:
import tensorflow
替换为:
import tensorflow.compat.v1
2.如果你导入Tensorflow模块的代码为:
import tensorflow as tf
则替换为
import tensorflow.compat.v1 as tf

RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
pycharm 测试代码

import tensorflow as tf
import os
os.environ[‘TF_CPP_MIN_LOG_LEVEL’]=‘2’
hello=tf.constant(‘12222211’)
sess=tf.Session()
print(sess.run(hello))

但运行出错,显示
AttributeError: module ‘tensorflow’ has no attribute ‘Session’
后来发现是因为现在是 Tensorflow2.x 版本,在运行 Session 语句时,需要执行下面语句
sess=tf.compat.v1.Session()
但是新的问题又来了,出错显示
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
又有要重下tensorflow的,又有用keras的,但我感觉都很麻烦
最后发现只要在代码中加入下面一行
tf.compat.v1.disable_eager_execution()

import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello=tf.constant(‘Hello!Tensorflow’)
sess=tf.compat.v1.Session()
print(sess.run(hello))
问题解决
原因探寻
在查阅了 Tensorflow 官方文档后,官方给出的该语句作用是
This function can only be called before any Graphs, Ops, or Tensors have been created. It can be used at the beginning of the program for complex migration projects from TensorFlow 1.x to 2.x.
即把 Tensorflow 1.x 的工作迁移至 2.x

RuntimeError: tf.placeholder() is not compatible with eager execution.和没有placeholder函数解决方法
在新版本tensorflow (1.15.0,2.0及以上) 中由于没有tf.placeholder占位符,函数调用应为:
a = tf.compat.v1.placeholder(dtype=tf.float32)
但这样placeholder在运行时会被立刻执行发生报错,为了让它只作为一个定义而不被立刻运行,等到session部分再运行,应在前面加上:
tf.compat.v1.disable_eager_execution() # 使placeholder只被定义,防止placeholder立刻被执行

决ImportError: cannot import name “imread” from “scipy.misc”
1、安装低版本的scipy
先查看自己的scipy版本:
In [21]: import scipy
In [22]: print(scipy.version)
1.4.1
目前的环境下安装的1.4.1版本,可以降级为较低版本:
pip install scipy==1.21
安装完重启软件即可。
2、使用另一个库imageio
那我们只能另寻他法了。
import imageio
imageio.imread()

pip3 install imageio -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com(cmd下)

不降级解决ModuleNotFoundError: No module named ‘tensorflow.contrib‘
在TensorFlow2.x版本已经不能使用contrib包

import tensorflow.contrib.slim as slim
使用该包时报错如下
ModuleNotFoundError: No module named ‘tensorflow.contrib’
解决(该方法仅适用于解决contrib下slim调用问题,其他包请参考文末版本迁移说明,在新的路径调用)
用如下语句下载镜像包
pip install --upgrade tf_slim
将import tensorflow.contrib.slim as slim
改为import tf_slim as slim
已安装tf-slim但仍报错,如何解决?(语言-python)
python找了很多办法解决no, module named tf_slim,但最终都是安装好tf-slim后结束

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐