在Tensorflow2.0环境中运行以下代码:
grads = K.gradients(model.output[:,0], last_conv_layer.output)[0]
报错:
tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.
解决方案:
使用tf1的compat模式禁用eager-execution约束表单tf2,添加如下代码:
import tensorflow as tf tf.compat.v1.disable_eager_execution()



