tensorflow1.0和tensorflow2.0兼容问题
tensorflow1.0和tensorflow2.0兼容问题方法一# 将import tensorflow as tf改成下面两条语句即可import tensorflow.compat.v1 as tftf.disable_v2_behavior()方法二对应的语句替换tensorflow1.0tensorflow2.0tf.truncated_normal()tf.random.trunca
·
tensorflow1.0和tensorflow2.0兼容问题
方法一
出现The Session graph is empty. Add operations to the graph before calling run().报错时
# 将import tensorflow as tf改成下面两条语句即可
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
或者
出现module 'tensorflow' has no attribute 'enable_eager_execution'报错时
# 将import tensorflow as tf改成下面两条语句即可
import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()
方法二
对应的语句替换
| tensorflow1.0 | tensorflow2.0 |
|---|---|
tf.truncated_normal() |
tf.random.truncated_normal() |
tf.placeholder() |
tf.compat.v1.placeholder () |
tf.train.AdamOptimizer(alpha).minimize(self.cost) |
tf.optimizers.Adam(alpha).minimize(self.cost) |
更多推荐

所有评论(0)