RuntimeError: `loss` passed to Optimizer.compute_gradients should be a function when eager execution is enabled.

In Tensorflow 2.0, eager execution is enabled by default.
在Tensorflow 2.0 中,eager execution 是默认开启的

 

tf.compat.v1.disable_eager_execution()

将这行代码放在整段前面

posted @ 2022-04-22 14:11  XmartinZK  阅读(681)  评论(0)    收藏  举报
1