首先一定要安装keras2.1.6
然后代码:
import keras
import keras_applications as m
#from keras.layers import ReLU
from keras.layers import DepthwiseConv2D
import coremltools.converters.keras as k
from keras.utils.generic_utils import CustomObjectScope
def ss():
model = k.convert("weight_and_structure.hdf5",
input_names=['input'],
output_names=['output'],
model_precision='float16')
def convert():
with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,
'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):
model = k.convert("weight_and_structure.hdf5",
input_names="image",
image_input_names="image",
image_scale=1 / 255.0,
class_labels='classlabel.txt',
is_bgr=True)
model.save('ss.mlmodel')
if __name__=='__main__':
convert()