tensorflow2.0版本 module 'tensorflow' has no attribute 'global_variables_initializer'问题解决
tf.initialize_all_variables()改为如下:
tf.compat.v1.global_variables_initializer()
2.0版本新旧对比:
https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0
TensorFlow数据运算错误——The Session graph is empty. Add operations to the graph before calling run()
在利用TensorFlow2.x中进行计算时,可能会出现这种错误“RuntimeError: The Session graph is empty. Add operations to the graph before calling run()”
问题产生原因:
tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.未对计算后的结果进行 tf.constant() 转换
解决办法:
tf.compat.v1.disable_eager_execution()
示例代码:
将原始代码与改进后的代码进行对比,即可发现问题所在:
1.原始问题代码:
# TensorFlow实现加法运算
a_t = tf.constant(2)
b_t = tf.constant(3)
c_t = a_t + b_t
#