gpt4 book ai didi

python - 使用已安装的环境将 Keras 模型转换为 coreml 时出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 19:56:33 26 4
gpt4 key购买 nike

我有一个 Keras 模型,并且正在按照 coreml 文档将其转换为 coreml。这是代码 - -

import coremltools
import tensorflow
from tensorflow import keras
coreml_model = coremltools.converters.keras.convert("basic.keras.h5")
coremltools.utils.save_spec(coreml_model, 'basic_v1.mlmodel')

但是运行它会给我带来很多错误,我认为这些错误与计算机上的环境有关。我的 Mac 上有 python 2,我安装了 python3 并正在使用它。我还安装了tensor flow 2(网站上的最新版本)。这是我得到的错误--

W1227 10:13:28.989016 4604394944 __init__.py:74] TensorFlow version 2.0.0 detected. Last version known to be fully compatible is 1.14.0 .
W1227 10:13:29.083386 4604394944 __init__.py:128] Keras version 2.3.1 detected. Last version known to be fully compatible of Keras is 2.2.4 .
Traceback (most recent call last):
File "convert_to_coreml.py", line 4, in <module>
coreml_model = coremltools.converters.keras.convert("basic.keras.h5")
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 792, in convert
respect_trainable=respect_trainable)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 579, in convertToSpec
respect_trainable=respect_trainable)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/coremltools/converters/keras/_keras2_converter.py", line 317, in _convert
model = _keras.models.load_model(model, custom_objects = custom_objects)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/saving.py", line 584, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/saving.py", line 274, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/saving.py", line 627, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
list(custom_objects.items())))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/sequential.py", line 301, in from_config
custom_objects=custom_objects)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 149, in deserialize_keras_object
return cls.from_config(config['config'])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1179, in from_config
return cls(**config)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/layers/core.py", line 877, in __init__
self.kernel_initializer = initializers.get(kernel_initializer)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/initializers.py", line 515, in get
return deserialize(identifier)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/initializers.py", line 510, in deserialize
printable_module_name='initializer')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 140, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown initializer: GlorotUniform

我不是一个Python专家,但最后一行指向一些Keras问题(根据谷歌),但我正在导入Keras,并且版本似乎没问题。如有任何帮助,我们将不胜感激。

最佳答案

您正在尝试使用glorot_uniform.h5 文件编写器和读取器使用的库版本不相同,并且不兼容。

你执行了

from tensorflow import keras

@lintex 提供 advice改为:

import keras

关于python - 使用已安装的环境将 Keras 模型转换为 coreml 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59504713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com