“无法解释优化器标识符"; Keras中的错误 [英] "Could not interpret optimizer identifier" error in Keras

查看:1634
本文介绍了“无法解释优化器标识符"; Keras中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在Keras中修改SGD优化器的学习率参数时出现此错误.我是否错过了代码中的某些内容,或者我的Keras安装不正确?

I got this error when I tried to modify the learning rate parameter of SGD optimizer in Keras. Did I miss something in my codes or my Keras was not installed properly?

这是我的代码:

from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, Flatten, GlobalAveragePooling2D, Activation
import keras
from keras.optimizers import SGD

model = Sequential()
model.add(Dense(64, kernel_initializer='uniform', input_shape=(10,)))
model.add(Activation('softmax'))
model.compile(loss='mean_squared_error', optimizer=SGD(lr=0.01), metrics= ['accuracy'])*

,这是错误消息:

回溯(最近通话最近):文件 "C:\ TensorFlow \ Keras \ ResNet-50 \ test_sgd.py",第10行,在 model.compile(loss ='mean_squared_error',Optimizer = SGD(lr = 0.01),metrics = ['accuracy'])文件 "C:\ Users \ nsugiant \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ keras_impl \ keras \ models.py", 787行,正在编译 ** kwargs)文件"C:\ Users \ nsugiant \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ keras_impl \ keras \ engine \ training.py", 编译中的第632行 self.optimizer = Optimizers.get(optimizer)文件"C:\ Users \ nsugiant \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ keras_impl \ keras \ optimizers.py", 788行,进入 引发ValueError('无法解释优化器标识符:',标识符)ValueError :('无法解释优化器标识符:', )

Traceback (most recent call last): File "C:\TensorFlow\Keras\ResNet-50\test_sgd.py", line 10, in model.compile(loss='mean_squared_error', optimizer=SGD(lr=0.01), metrics=['accuracy']) File "C:\Users\nsugiant\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\keras_impl\keras\models.py", line 787, in compile **kwargs) File "C:\Users\nsugiant\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\keras_impl\keras\engine\training.py", line 632, in compile self.optimizer = optimizers.get(optimizer) File "C:\Users\nsugiant\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\keras_impl\keras\optimizers.py", line 788, in get raise ValueError('Could not interpret optimizer identifier:', identifier) ValueError: ('Could not interpret optimizer identifier:', )

推荐答案

我最近遇到了类似的问题.

I recently faced similar problem.

原因是您将tensorflow.python.keras api用于模型和图层,并将keras.optimizers用于SGD.它们是tensorflow和纯keras的两种不同的keras版本.他们无法一起工作.您必须将所有内容更改为一个版本.然后它应该工作. :)

The reason is you are using tensorflow.python.keras api for model and layers and keras.optimizers for SGD. They are two different keras versions of tensorflow and pure keras. They could not work together. You have to change everything to one version. Then it should work. :)

希望这会有所帮助.

这篇关于“无法解释优化器标识符"; Keras中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆