如何修复此值错误“ValueError:在新的 Keras 优化器中已弃用衰减”?

Bub*_*les 6 model face-recognition deep-learning keras tensorflow

我是深度学习的新手,我遵循有关人脸检测的教程。

model = canaro.models.createSimpsonsModel(IMG_SIZE=IMG_SIZE, channels=channels, output_dim=len(characters), 
                                         loss='binary_crossentropy', decay=1e-7, learning_rate=0.001, momentum=0.9,
                                         nesterov=True)


Run Code Online (Sandbox Code Playgroud)

ValueError Traceback(最近一次调用最后)警告:absl:lr已弃用,请改用learning_rate,或使用旧版优化器,例如 tf.keras.optimizers.legacy.SGD。输出超出大小限制。在文本编辑器中打开完整的输出数据 ValueError: Decay 在新的 Keras 优化器中已被弃用,请检查文档字符串以获取有效参数,或使用旧版优化器,例如 tf.keras.optimizers.legacy.SGD。

我已经尝试遵循一些步骤,但我不知道如何解决它。

Sal*_*lli 9

正如其他地方提到的,decay自 Keras 2.3 以来,所有优化器都已弃用该参数,其发行说明明确建议使用LearningRateSchedule对象。

由于您显然无法修改canaro源代码(嗯......您可以,但这是非常糟糕的做法,并且绝对推荐),我看到两个选择:

  1. 将 Tensorflow 降级到使用 Keras 后端 <2.3 的版本
  2. 如果可能,将canaro升级到支持 TF 2.3+ 的版本

对于那些在 Google 搜索后遇到这个问题并且仍然可以修改其源代码的人(也就是说,他们并不特别担心canaro ),这里有一个示例片段:

TF<2.3 - 样式

import tensorflow as tf
epochs = 50
learning_rate = 0.01
decay_rate = learning_rate / epochs
optimizer = tf.keras.optimizers.Adam(lr=learning_rate, decay=decay_rate)
Run Code Online (Sandbox Code Playgroud)

TF>=2.3 - 样式

import tensorflow as tf
lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(
    initial_learning_rate=0.01,
    decay_steps=10000,
    decay_rate=0.9)
optimizer = tf.keras.optimizers.Adam(learning_rate=lr_schedule)
Run Code Online (Sandbox Code Playgroud)


小智 5

看起来您正在尝试使用一个相当旧的深度学习库,该库显然已经过时并且最近没有维护。您看到的错误是由于该特定库使用的 API 是用旧版本的 tensorflow (<=2.3) 编写的,该版本现已弃用。如果你想解决这个问题,你必须手动降级你的张量流或修改该库的源代码canaro