我正在尝试.mlmodel使用以下代码将 h5 keras 模型转换为文件类型:
from keras.models import load_model
import keras
from keras.applications.mobilenet import MobileNet
from keras.layers import DepthwiseConv2D
# convert the model to coreml format
print("[INFO] converting model")
from keras.utils.generic_utils import CustomObjectScope
with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):
model = load_model('/Users/nikhil.c/aslModel.h5', custom_objects={
'relu6': MobileNet})
coreml_model = coremltools.converters.keras.convert("/Users/nikhil.c /aslModel.h5",
input_names="image",
image_input_names="image",
image_scale=1/255.0,
class_labels= ["hello", "hi", "you"],
is_bgr=True)
# save the model to disk
coremltools.utils.save_spec(coreml_model, 'aslModel.mlmodel')
在使用之前,我最初收到此错误CustomObjectScope:
ImportError: cannot import name 'relu6'
我通过修复它CustomObjectScope,但现在我收到错误:
AttributeError: module 'keras.applications.mobilenet' has no attribute 'relu6'.
我通常不会在堆栈溢出中发帖,所以如果您需要更多信息,请告诉我。
Cats萌萌
相关分类