我试图将我的模型转换,而不是加载到CoreML中,但它一直给我这个错误,我不知道如何修复它。
下面是我的代码:
import keras
import coremltools
import tensorflow as tf
model = tf.keras.models.load_model('machine')
print(model.summary())
output_labels = ['0', '1']
model = coremltools.converters.keras.convert('machine', input_names=
['text'], output_names=['output'])
model.author = 'Aarush'
model.short_description = 'My model'
model.input_description['text'] = 'Takes text as an input'
model.output_description['output'] = 'Prediction of CyberBullying
sentiment'
model.save('xcodeModel.mlmodel')
ERROR:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-62-5bde9de3c9f8> in <module>()
1 output_labels = ['0', '1']
2
----> 3 model = coremltools.converters.keras.convert('machine', input_names=['text'], output_names=['output'])
4
5 model.author = 'Aarush'
21 frames
/usr/local/lib/python3.6/dist-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
138 if cls is None:
139 raise ValueError('Unknown ' + printable_module_name +
--> 140 ': ' + class_name)
141 if hasattr(cls, 'from_config'):
142 custom_objects = custom_objects or {}
ValueError: Unknown initializer: GlorotUniform附注:
我试过做import keras、tf.keras和createObject,但他们都不起作用。任何帮助都将不胜感激。
谢谢
发布于 2020-01-16 20:35:34
转换的keras核心工具仅支持keras模型,不支持tf.keras。对于后一个库,您需要使用tensorflow转换器,并使用以下函数:
coremltools.converters.tensorflow.convert有关更多信息,请参阅源代码here的注释。您还需要转换参数,因为它需要一个模型文件名(一个.h5),而不是一个模型实例。例如:
import coremltools
from tensorflow.keras.applications import ResNet50
model = coremltools.converters.tensorflow.convert(
'./model.h5',
input_name_shape_dict={'input_1': (1, 224, 224, 3)},
output_feature_names=['Identity']
)https://stackoverflow.com/questions/59763619
复制相似问题