【发布时间】:2020-01-24 03:29:51
【问题描述】:
我尝试了各种方法来使用 core ml 工具将我的 Keras 模型转换为 core ml,但它给了我这个错误。
不支持 Keras 层。
我正在尝试将 .h5 模型转换为核心 ml,以便我可以在我的应用程序中使用它,但它给了我一些我无法解决的错误。另外,我尝试将 .h5 模型转换为 PB(冻结图),但那里出现错误。
这就是我的模型的外观。
img_input = layers.Input(shape=(224, 224, 3))
seed = 230
numpy.random.seed(seed)
x = layers.Conv2D(16, 3, activation='relu')(img_input)
x = layers.MaxPooling2D(2)(x)
x = layers.Conv2D(32, 3, activation='relu')(x)
x = layers.MaxPooling2D(2)(x)
x = layers.Flatten()(x)
x = layers.Dense(128, activation='relu')(x)
x = layers.Dropout(0.4)(x)
output = layers.Dense(3, activation='softmax')(x)
model = Model(img_input, output)
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
这是我在网上找到的将 Keras 模型转换为核心机器学习工具的代码。
导入 keras 导入coremltools
fcn_mlmodel = coremltools.converters.keras.convert(model, input_names = 'image', image_input_names = 'image', output_names = 'class_label')
fcn_mlmodel.input_description['image']="图像大小(224,224,3)"
fcn_mlmodel.output_description['class_label']="类标签"
fcn_mlmodel.save("Test_my.mlmodel")
错误:不支持 Keras 层。 ——
【问题讨论】:
-
欢迎来到 SO;您的模型看起来如何与您的问题无关;请发布您使用您提到的转换工具所尝试的具体内容,以及遇到的问题
-
@desertnaut 这是我在网上找到的将 Keras 模型转换为核心机器学习工具的代码。 import keras import coremltools model.summary() fcn_mlmodel = coremltools.converters.keras.convert( model, input_names = 'image', image_input_names = 'image', output_names = 'class_label' ) fcn_mlmodel.input_description['image']="Image size (224,224,3)" fcn_mlmodel.output_description['class_label']="Class label" fcn_mlmodel.save("Test_my.mlmodel") Err: Keras layer '
' 不支持。 -
请不要在 cmets 空间中发布代码 - 它实际上是不可读的! 编辑和更新您的帖子。