【问题标题】:K.gradients is not supported when eager execution is enabled. use GradientTape instead. How do i replace it directly in my code启用 Eager Execution 时不支持 K.gradients。改用 GradientTape。我如何直接在我的代码中替换它
【发布时间】:2022-02-26 16:03:22
【问题描述】:

下面提到的是我的代码行。第 1 行初始化自定义 VGG16 模型(所有最大池层都替换为平均池。第 1 行也初始化目标。第 3 行制定损失函数,第 4 行是抛出错误的行

content_model = VGG16_AvgPool_CutOff(shape, 11)
target = K.variable(content_model.predict(x))
loss = K.mean(K.square(target - content_model.output))
grads = K.gradients(loss, content_model.input)

错误:

tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.

感谢您的帮助,谢谢!

【问题讨论】:

    标签: machine-learning deep-learning neural-network conv-neural-network tensorflow2.0


    【解决方案1】:

    如报错,请使用GradientTape代替gradients,因为在tensorflow eager模式下不支持gradients,如果你使用Tensorflow > 2.0

    grads = tf.GradientTape(loss, content_model.input)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2020-09-21
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多