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#
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.
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.”
Flexible Input Shapes#
Composite and Custom Operators#
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#
Compiled Model Timing Example: Demonstrates timing differences with calling a large model.
Xcode Model Preview Types#
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.