loss
passed to Optimizer.compute_gradients should be a function when eager execution is enabl这是因为tensorflow版本的问题,tensorflow1和tensorflow2中的代码略有不同,更换部分代码即可
loss = tf.reduce_mean(tf.square(y-y_data))
optimizer = tf.compat.v1.train.GradientDescentOptimizer(0.5)
# #tf.compat.v1.disable_eager_execution()
train = optimizer.minimize(loss)
loss = lambda: tf.keras.losses.MSE(y_data, Weights * x_data + biases)
optimizer = tf.keras.optimizers.SGD(learning_rate=0.5)
这是小问题,继续学习!