美文网首页
Keras转换为CoreML model

Keras转换为CoreML model

作者: 咸鱼有只喵 | 来源:发表于2019-04-26 18:09 被阅读0次

首先一定要安装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()

相关文章

网友评论

      本文标题:Keras转换为CoreML model

      本文链接:https://www.haomeiwen.com/subject/kliqnqtx.html