The following are code example snippets and full examples of using Core ML Tools to convert models.
|For a quick start
|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
|Typed Execution Workflow Example: Demonstrates a workflow for checking accuracy using ML Programs with Typed Execution.
|Load and Convert a Model (in Unified Conversion API)
TensorFlow 2 Workflow
Convert a Pre-trained Model
Convert a User-defined Model
Getting Started: Demonstrates how to convert an image classifier model trained using the TensorFlow Keras API to the Core ML format.
Converting TensorFlow 2 BERT Transformer Models: Converts an object of the tf.keras.Model class and a SavedModel in the TensorFlow 2 format.
|Convert From TensorFlow 1 (in Unified Conversion API)
Export as Frozen Graph and Convert
Convert a Pre-trained Model
Converting a TensorFlow 1 Image Classifier: Demonstrates the importance of setting the image preprocessing parameters correctly during conversion to get the right results.
Converting a TensorFlow 1 DeepSpeech Model: Demonstrates automatic handling of flexible shapes using automatic speech recognition.
|Convert from PyTorch (in Unified Conversion API)
Converting from PyTorch
Converting a Natural Language Processing Model: Combines tracing and scripting to convert a PyTorch natural language processing model.
Converting a torchvision Model from PyTorch: Traces a torchvision MobileNetV2 model, adds preprocessing for image input, and then converts it to Core ML.
Converting a PyTorch Segmentation Model: Converts a PyTorch segmentation model that takes an image and outputs a class prediction for each pixel of the image.
|Model Intermediate Language (MIL)
|Model Intermediate Language: Construct a MIL program using the Python builder.
Convert a Model with a MultiArray
Convert a Model with an ImageType
Add Image Preprocessing Options
Classifiers: Produce a Classifier Model
Flexible Input Shapes:
Select from Predetermined Shapes
Set the Range for Each Dimension
Update a Core ML Model to Use Flexible Input shapes
Composite Operators: Defining a composite operation by decomposing it into MIL operations.
Custom Operators: Augment Core ML with your own operators and implement them in Swift.
|Training-Time Compression Examples: Use magnitude pruning, linear quantization, or palettization while training your model, or start from a pre-trained model and fine-tune it with training data.
Compressing Neural Network Weights: Reduce the size of a neural network by reducing the number of bits that represent a number.
|Trees and Linear Models
Load and save the MLModel
Use the MLModel for Prediction
Work with the spec Object
Update the Metadata and Input/output Descriptions
Image Prediction for a Multi-array Model
Xcode Model Preview Types:
BERT QA Example
Body Pose Example
Rename a Feature
Convert All Double Multi-array Feature Descriptions to Float
Evaluate Classifier, Regressor, and Transformer models
|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.