解决module ‘tensorflow‘ has no attribute ‘...‘系列
Posted TLY-101-010
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决module ‘tensorflow‘ has no attribute ‘...‘系列相关的知识,希望对你有一定的参考价值。
解决module ‘tensorflow‘ has no attribute ‘...‘系列
- 解决module ‘tensorflow’ has no attribute ‘Session’
- 解决module ‘tensorflow’ has no attribute ‘contrib’
- 解决module ‘tensorflow’ has no attribute ‘reset_default_graph’
- 解决module 'tensorflow' has no attribute 'set_random_seed'
- 解决module 'tensorflow' has no attribute 'get_variable'
- 解决module 'tensorflow' has no attribute 'placeholder'
- 解决module 'time' has no attribute 'clock'
- 解决module 'tensorflow' has no attribute 'global_variables_initializer'
- 解决'tensorflow' 调用优化算法Adam
解决module ‘tensorflow’ has no attribute ‘Session’
原代码
// 创建一个session并运行它
sess = tf.Session()
result = sess.run(Y)
// session使用完毕,关闭它
sess.close()
修改后
// 创建一个session并运行它
sess = tf.compat.v1.Session()
result = sess.run(Y)
// session使用完毕,关闭它
sess.close()
再次修改
// 创建一个session,运行,自动关闭
with tf.compat.v1.Session() as sess:
result = sess.run(Y)
解决module ‘tensorflow’ has no attribute ‘contrib’
针对:tf.contrib.layers.variance_scaling_initializer
原代码
tf.contrib.layers.variance_scaling_initializer()
修改后
tf.initializers.GlorotUniform()
解决module ‘tensorflow’ has no attribute ‘reset_default_graph’
原代码
tf.reset_default_graph()
修改后
tf.compat.v1.reset_default_graph()
解决module ‘tensorflow’ has no attribute ‘set_random_seed’
原代码
tf.set_random_seed(1)
修改后
tf.random.set_seed(1)
解决module ‘tensorflow’ has no attribute ‘get_variable’
原代码
tf.get_variable()
修改后
tf.compat.v1.get_variable()
解决module ‘tensorflow’ has no attribute ‘placeholder’
原代码
tf.placeholder()
修改后
tf.compat.v1.placeholder()
解决module ‘time’ has no attribute ‘clock’
原代码
time.clock()
修改后
time.perf_counter()
//或者
time.process_time()
解决module ‘tensorflow’ has no attribute ‘global_variables_initializer’
原代码
tf.global_variables_initializer()
修改后
tf.compat.v1.global_variables_initializer()
解决’tensorflow’ 调用优化算法Adam
原代码
tf.train.AdamOptimizer
修改后
tf.compat.v1.train.AdamOptimizer
成功解决AttributeError: module ‘tensorflow‘ has no attribute ‘reset_default_graph‘daiding
成功解决AttributeError: module \'tensorflow\' has no attribute \'reset_default_graph\'daiding
目录
解决问题
tf.reset_default_graph()
AttributeError: module \'tensor
以上是关于解决module ‘tensorflow‘ has no attribute ‘...‘系列的主要内容,如果未能解决你的问题,请参考以下文章
成功解决AttributeError: module ‘tensorflow‘ has no attribute ‘reset_default_graph‘daiding
tf.Session()提示module 'tensorflow' has no attribute 'Session'如何解决?
AttributeError: module ‘tensorflow._api.v2.io.gfile’ has no attribute ‘get_filesystem’
解决AttributeError: module ‘tensorflow_gan.python.eval‘ has no attribute ‘classifier_fn_from_tfhub‘
解决AttributeError: module ‘tensorflow_gan.python.eval‘ has no attribute ‘classifier_fn_from_tfhub‘(代码
AttributeError: module ‘tensorflow‘ has no attribute ‘get_default_graph‘