某些API随着tensorflow版本的提高而带来使用的改变
1.module ‘tensorflow’ has no attribute 'reset_defaultt_graph’错误
解决方法1:
在import tensorflow as tf 后面
添加:
from tensorflow.python.framework import ops
ops.reset_default_graph()
解决方法2:
将import tensorflow as tf
更改为:import tensorflow.compat.v1 as tf
将tf.reset_default_graph()
更改为:tf.compat.v1.reset_default_graph()
解决方法3:tensorflow版本与kerase版本对应
2.AttributeError: module ‘tensorflow_core._api.v2.nn’ has no attribute ‘rnn_cell’错误
解决方法:
将tf.nn.rnn_cell.BasicLSTMCell()
更改为:tf.compat.v1.nn.rnn_cell.BasicLSTMCell
3.AttributeError: module ‘tensorflow_core._api.v2.train’ has no attribute ‘AdamOptimizer’错误
解决方法:
将tf.train.AdamOptimizer(learning_rate=0.002).minimize(cost)
更改为:tf.compat.v1.train.AdamOptimizer(learning_rate=0.002).minimize(cost)
4.找不到compat模块
由于将import tensorflow as tf
更改为:
import tensorflow.compat.v1 as tf
tf.disable_v2_behaviour() 产生找不到compat模块错误
解决方法:
将import tensorflow as tf
更改为:import tensorflow as tf2
tf = tf2.compat.v1
tf.disable_v2_behavior()
直接推 放弃1.x版本代码 重新学习2.x的