如何修复此数值错误 ‘ ValueError: 在新的Keras优化器中,衰减已被弃用’?

huangapple go评论113阅读模式
英文:

How to fix this value error ' ValueError: decay is deprecated in the new Keras optimizer'?

问题

我在跟随一个关于深度计算机视觉的YouTube教程。

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

我还遇到了以下错误:

> ValueError: 衰减(decay)已在新的Keras优化器中弃用,请查阅文档字符串以获取有效的参数,或使用旧的优化器,例如tf.keras.optimizers.legacy.SGD

我正在使用Kaggle笔记本。我尝试降级tensorflow,使用tf.keras.optimizers.SGD和其他一些方法。我是深度学习新手,不知道如何修复它。

作为最后的手段,我该如何修改源代码?

我感谢帮助:)。


<details>
<summary>英文:</summary>

I was following a youtube tutorial on Deep computer vision.

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

I also get the following error:



&gt;ValueError: decay is deprecated
 in the new Keras optimizer, 
please check the docstring for valid arguments,
 or use the legacy optimizer, 
e.g., tf.keras.optimizers.legacy.SGD.


I am using Kaggle notebook. I tried downgrading tensorflow, using &#39;tf.keras.optimizers.SGD&#39; and a few other things. I am new to deep learning and don&#39;t know how to fix it. 

As a last resort, how can I modify the source code? 

I appreciate the help : ).

</details>


# 答案1
**得分**: 1

"ValueError: `decay is deprecated in the new Keras optimizer`" 这个错误是在使用仍然支持优化器中的decay参数的旧版本Keras时出现的。要解决这个错误,您可以尝试将Keras更新到新版本,或者在优化器中使用learning_rate参数代替decay。

如果更新Keras不是一个选项,您还可以尝试使用`tf.keras.optimizers.legacy`中的遗留优化器。例如:

```python
optimizer = tf.keras.optimizers.legacy.SGD(lr=learning_rate, decay=decay, momentum=momentum, nesterov=nesterov)
英文:

The error "ValueError: decay is deprecated in the new Keras optimizer&quot; occurs when using an old version of Keras that still supports the decay argument in the optimizer . To solve this error, you can try updating Keras to a newer version or using the learning_rate argument instead of decay in the optimizer.

You can also try using a legacy optimizer from tf.keras.optimizers.legacy if updating Keras is not an option for you. For example:

optimizer = tf.keras.optimizers.legacy.SGD(lr=learning_rate, decay=decay, momentum=momentum, nesterov=nesterov)

huangapple
  • 本文由 发表于 2023年7月11日 04:39:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76657191.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定