loss = tf.reduce_mean(tf.square(y - y_data))
出错:
`loss` passed to Optimizer.compute_gradients should be a function when eager execution is enabled.
错误原因:Tensorflow 版本问题
在Tensorflow 2.0 中,eager execution 是默认开启的。
需要先关闭eager execution
import tensorflow.compat.v1 as tf
tf.disable_eager_execution()