coremltools

Use Core ML to integrate machine learning models into your app. Core ML provides a unified representation for all models. Your app uses Core ML APIs and user data to make predictions, and to train or fine-tune models, all on the user’s device.

Core ML optimizes on-device performance by leveraging the CPU, GPU, and Neural Engine while minimizing its memory footprint and power consumption. Running a model strictly on the user’s device removes any need for a network connection, which helps keep the user’s data private and your app responsive.

Multi-backend Keras

Models created via the Multi-backend Keras with a TensorFlow 1.x backend, and saved in the .h5 format can be converted to Core ML. Since this version of Keras is only supported until April 2020, this convertor has not been moved to the Unified Conversion API and will be in maintenance mode. Additional features to coremltools will not be added to this converter.

❗️

Keras and Tensorflow.Keras can be easily confused

Multi-backend Keras is the version of Keras that supported multiple backends including CNTK and Theano, while the TensorFlow Keras API only supports TensorFlow. Do not confuse these two packages.

📘

Using Keras APIs with Tensorflow 2 backend

If you are using Keras APIs with Tensorflow 2, instead use the tf.keras APIs directly, and convert the resulting tf.keras model with the unified conversion API.

The coremltools Keras converter supports Keras versions 2.2+, since they are the only maintained versions of Keras.

import coremltools as ct

# Convert by providing path to a .h5 file
model = ct.converters.keras.convert('keras_model.h5')

# Convert by providing a Keras model object
from keras.models import load_model
keras_model = load_model("keras_model.h5")

model = ct.converters.keras.convert(keras_model)

For a complete list of arguments that can be passed to the convert() method, see here or at the function signature in code.

Updated 3 months ago


What's Next

TensorFlow

Multi-backend Keras


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.