【发布时间】:2018-10-10 10:13:59
【问题描述】:
我们正在尝试将 .h5 Keras 模型转换为 .mlmodel 模型,我的代码如下:
from keras.models import load_model
import keras
from keras.applications import MobileNet
from keras.layers import DepthwiseConv2D
from keras.utils.generic_utils import CustomObjectScope
with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):
model = load_model('CNN_tourist_11.h5', custom_objects={'relu6': MobileNet})
output_labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
coreml_model = coremltools.converters.keras.convert("CNN_tourist_11.h5",
input_names="image",
image_input_names="image",
class_labels= output_labels,)
coremltools.utils.save_spec(coreml_model, 'place10.mlmodel')
我们查找6天前提出的类似问题,我们也导入了MobileNet,但仍然显示此错误:
AttributeError: module 'keras.applications.mobilenet' has no attribute 'relu6'
我的 TensorFlow 版本是 1.10.0 而 Keras 版本是 2.2.2
如果有人能就为什么一直显示此错误向我们提供建议,我们将不胜感激,非常感谢。
【问题讨论】:
-
这个问题之前已经回答过了,请在提问前先搜索类似的,看看答案是否已经在这里了。
-
@MatiasValdenegro 我看到了 6 天前提出的问题,我做了你建议的“从 keras.applications 导入 MobileNet”,但它仍然不起作用。对不起,类似的问题,但我确实查找了这个问题,谢谢。
-
那么你需要具体说明什么不起作用,尽可能地为你的问题添加更多细节。
-
@MatiasValdenegro 我已经修改了我的问题,感谢您的提醒。
标签: keras coremltools relu