无法将 Keras 模型转换为 Coreml
Can't convert Keras model to Coreml
我尝试了多种方法使用 core ml 工具将我的 Keras 模型转换为 core ml,但它给了我这个错误。
Keras layer '' not supported.
我正在尝试将 .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(损失='sparse_categorical_crossentropy', 优化器='adam', 指标=['accuracy'])
这是我在网上找到的将 Keras 模型转换为核心 ml 工具的代码。
导入keras
导入 coremltools
fcn_mlmodel = coremltools.converters.keras.convert( 模型, 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标签"
fcn_mlmodel.save("Test_my.mlmodel")
错误:不支持 Keras 层“”。 –
无法重现您的问题,复制了所有内容。可能是你的版本问题:
pip install -U coremltools==3.0b6 tensorflow==1.13.1 keras==2.2.4
一起工作很好。
我尝试了多种方法使用 core ml 工具将我的 Keras 模型转换为 core ml,但它给了我这个错误。
Keras layer '' not supported.
我正在尝试将 .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(损失='sparse_categorical_crossentropy', 优化器='adam', 指标=['accuracy'])
这是我在网上找到的将 Keras 模型转换为核心 ml 工具的代码。
导入keras 导入 coremltools
fcn_mlmodel = coremltools.converters.keras.convert( 模型, 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标签"
fcn_mlmodel.save("Test_my.mlmodel")
错误:不支持 Keras 层“”。 –
无法重现您的问题,复制了所有内容。可能是你的版本问题:
pip install -U coremltools==3.0b6 tensorflow==1.13.1 keras==2.2.4
一起工作很好。