Keras load_model returning Unexpected keyword argument passed to optimizer: amsgrad

时间:2018-01-15 18:13:50

标签: python tensorflow keras

I'm trying to load a model trained with keras by running:

model = load_model('model.h5')

but I get the following:

File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 258, in load_model
custom_objects=custom_objects)
File "/usr/local/lib/python3.5/dist-packages/keras/optimizers.py", line 689, in deserialize
printable_module_name='optimizer')
File "/usr/local/lib/python3.5/dist-packages/keras/utils/generic_utils.py", line 142, in deserialize_keras_object
return cls.from_config(config['config'])
File "/usr/local/lib/python3.5/dist-packages/keras/optimizers.py", line 127, in from_config
return cls(**config)
File "/usr/local/lib/python3.5/dist-packages/keras/optimizers.py", line 403, in __init__
super(Adam, self).__init__(**kwargs)
File "/usr/local/lib/python3.5/dist-packages/keras/optimizers.py", line 63, in __init__
'passed to optimizer: ' + str(k))
TypeError: Unexpected keyword argument passed to optimizer: amsgrad

I'm using Keras 2.1.2 and tensorflow 1.4.1

2 个答案:

答案 0 :(得分:11)

AMSgrad已于2017年12月11日添加到Keras https://github.com/keras-team/keras/pull/8693,而Keras 2.1.2已于2012年12月1日建成https://github.com/keras-team/keras/releases/tag/2.1.2

因此,如果模型使用它,您需要等待下一个版本或从头开始安装Keras。

答案 1 :(得分:6)

需要Keras版本2.1.3,因此您可以使用

pip install keras==2.1.3