AttributeError: ‘RefVariable‘ object has no attribute ‘_id‘--使用Tensorflow2.0版本(及时执行模式)

在使用tensorflow2.0版本的框架时,一般默认为即使执行模式。但有时候还是像tensorflow1.x版本一样,必须在导入库函数之后,调用函数:tf.enable_eager_execution()才能启用及时执行模式,否则会导致如下类似错误。

在这里插入图片描述
一般遇到上述问题,只需要在import tensorflow as tf 的语句后面加上:
tf.enable_eager_execution()
在这里插入图片描述
在这里插入图片描述