Examples#

The following are code example snippets and full examples of using Core ML Tools to convert models.

For a Quick Start#

Full example:

  • Getting Started: Demonstrates how to convert an image classifier model trained using the TensorFlow Keras API to the Core ML format.

ML Program with Typed Execution#

Full example:

TensorFlow 2#

Full examples:

TensorFlow 1#

Full examples:

PyTorch#

Full examples:

Model Intermediate Language (MIL)#

Full example:

Conversion Options#

Image Inputs#

Classifiers#

Flexible Input Shapes#

Composite and Custom Operators#

Full example:

  • Custom Operators: Augment Core ML with your own operators and implement them in Swift.

Optimization#

Full examples:

Trees and Linear Models#

MLModel#

MLModel Overview#

Model Prediction#

Full example:

Xcode Model Preview Types#

Full examples:

MLModel Utilities#

Updatable Models#

Full examples:

  • Nearest Neighbor Classifier: Create an updatable empty k-nearest neighbor.

  • Neural Network Classifier: Create a simple convolutional model with Keras, convert the model to Core ML, and make the model updatable.

  • Pipeline Classifier: Use a pipeline composed of a drawing-embedding model and a nearest neighbor classifier to create a model for training a sketch classifier. If you have a code example you’d like to submit, see Contributing.