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.kerasAPIs directly, and convert the resulting
tf.kerasmodel 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)
Updated 3 months ago