keras - 无法将 Keras 模型转换为 Coreml
问题描述
我尝试了各种方法来使用 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',优化器='adam',metrics=['accuracy'])
这是我在网上找到的将 Keras 模型转换为核心机器学习工具的代码。
导入 keras 导入 coremltools
fcn_mlmodel = coremltools.converters.keras.convert(模型,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 层。——</p>
解决方案
无法重现您的问题,复制了所有内容。可能是你的版本有问题:
pip install -U coremltools==3.0b6 tensorflow==1.13.1 keras==2.2.4
一起工作很好。
推荐阅读
- php - 使用 eloquent 在数据库中创建新数据条目并尝试访问 url 中的变量
- mongodb - 如何修复错误找不到模块'core-js/es6'
- java - Matcher java不起作用,但正则表达式似乎很好
- java - 从相同对象的两个列表中仅查找不匹配的 id
- sql - SQL 查询多列,仅在一列上使用 Distinct 并使用 Order By
- c++ - 在 Visual Studio 中通过 WSL 调试 cmake 项目时如何启用断点?
- android - sqlite 数据库代码在 Android 7.0 上工作,但在 Android 8.0 上失败
- javascript - 如何从 Enzyme/Sinon 的窗口导入配置变量?
- javascript - 应用折扣后找到购物车最低价格的算法
- google-apps-script - 有没有办法动态更新选项列表