pip install -U coremltools
下载一个caffe模型:
# Age and gender models
wget http://www.openu.ac.il/home/hassner/projects/cnn_agegender/cnn_age_gender_models_and_data.0.0.2.zip
unzip -a cnn_age_gender_models_and_data.0.0.2.zip
进行转换:
import coremltools
folder = 'cnn_age_gender_models_and_data.0.0.2'
coreml_model = coremltools.converters.caffe.convert(
(folder + '/age_net.caffemodel', folder + '/deploy_age.prototxt'),
image_input_names = 'data',
class_labels = 'ages.txt'
)
coreml_model.author = 'Gil Levi and Tal Hassner'
coreml_model.license = 'Unknown'
coreml_model.short_description = 'Age Classification using Convolutional Neural Networks'
coreml_model.input_description['data'] = 'An image with a face.'
coreml_model.output_description['prob'] = 'The probabilities for each age, for the given input.'
coreml_model.output_description['classLabel'] = 'The most likely age, for the given input.'
coreml_model.save('AgeNet.mlmodel')
https://github.com/apache/incubator-mxnet/tree/master/tools/coreml
https://github.com/onnx/onnx-coreml
最新版本安装:
git clone https://github.com/tf-coreml/tf-coreml/tf-coreml.git
cd tf-coreml
pip install -e
也可以用下面的命令进行安装:
python setup.py bdist_wheel
也可以安装PyPI包:
pip install -U tfcoreml
在编写自己的转换工具时,会涉及到从模型的输入、输出和架构表示方法至 Core ML 模型格式的转换。为此,您需要定义每一层的模型架构以及每一层与其他层的连接。以 Core ML 工具 (英文) 提供的转换工具为例,它们展示了如何将使用第三方框架创建的各种模型类型转换为 Core ML 模型格式。
注释
Core ML 模型格式由一组协议缓冲文件定义,详见“Core ML 模型规范 (英文)”。