解决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
文章出处登录后可见!
已经登录?立即刷新