英文:
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:
>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 'tf.keras.optimizers.SGD' and a few other things. I am new to deep learning and don'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" 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论