Coremltools:传递给优化器的意外关键字参数:learning_rate



我正在使用以下代码将keras模型转换为mlmodel:

import coremltools
import keras


output_labels = list(range(1, 43))
your_model = coremltools.converters.keras.convert('my_model.h5', input_names=['image'], output_names=['output'],
class_labels=output_labels, image_input_names='image')
#your_model.author = 'your name'
#your_model.short_description = 'Digit Recognition with MNIST'
#your_model.input_description['image'] = 'Takes as input an image'
#your_model.output_description['output'] = 'Prediction of Digit
your_model.save('your_model_name.mlmodel')

当运行代码时,我得到以下错误:

Users/admin/PycharmProjects/TSR37/venv/bin/python /Users/admin/PycharmProjects/TSR37/coremlconverter.py
Traceback (most recent call last):
File "/Users/admin/PycharmProjects/TSR37/coremlconverter.py", line 9, in <module>
class_labels=output_labels, image_input_names='image')
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 830, in convert
use_float_arraytype=use_float_arraytype,
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 607, in _convert_to_spec
use_float_arraytype=use_float_arraytype,
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/coremltools/converters/keras/_keras2_converter.py", line 353, in _convert
model = _keras.models.load_model(model, custom_objects=custom_objects)
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/keras/engine/saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/keras/engine/saving.py", line 299, in _deserialize_model
custom_objects=custom_objects)
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/keras/optimizers.py", line 768, in deserialize
printable_module_name='optimizer')
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
return cls.from_config(config['config'])
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/keras/optimizers.py", line 154, in from_config
return cls(**config)
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/keras/optimizers.py", line 460, in __init__
super(Adam, self).__init__(**kwargs)
File "/Users/admin/PycharmProjects/TSR37/venv/lib/python3.7/site-packages/keras/optimizers.py", line 79, in __init__
'passed to optimizer: ' + str(k))
TypeError: Unexpected keyword argument passed to optimizer: learning_rate
Process finished with exit code 1

为什么会这样,我该如何让它发挥作用?我试图更新keras和/或tensorflow,但coremltools似乎只适用于keras 2.2.4和tensorflow 1.15.0

这是通过在创建模型的环境和转换模型的环境中使用相同版本的keras和tensorflow来解决的。

相关内容

  • 没有找到相关文章