源码因为Tensorflow版本问题报错解决办法

当我们的项目在Tensorflow 1.0 的环境下写的,放在Tensorflow 2.0 环境下运行时出现报错,可以考虑下面的几种方法,绝对有效,亲测哦!

方法1:最直接的就是卸载当前的Tensorflow 2.0 版本,安装Tensorflow 1.0 版本;

方法2 :直接引入Tensorflow库时,改为以下方式:

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()

方法3:凡是运行报错出现因为Tensorflow没有相应模块的问题,都可以选择,在相应的地方添加:compat.v1,举个例子:

AttributeError: module 'tensorflow' has no attribute 'app'

原先是这样写的:

flags = tf.app.flags

改成这样写:flags = tf.compat.v1.flags;就没问题。

同样的,遇到类似的问题都可以这样操作。祝大家好运!

你可能感兴趣的:(TensorFlow)