About the Author
Introduction
Who Is This Book For?
Useful Links
- Part 1: The Core ML Ecosystem
What is Core ML — and What is It Not?
Core ML Version History
The Vision Framework and Core ML
The SoundAnalysis Framework
Where to Get mlmodels?
Create ML: The Easiest Way to Train
Turi Create — it’s Like Create ML but in Python
coremltools
- Part 2: Converting Models
Image Preprocessing
Converting TensorFlow / PyTorch With the Unified API
Keras Conversion Tips
Converting tf.keras With the Old Converter
Caffe Conversion Tips
TensorFlow 1.x Conversion With tfcoreml
TensorFlow 2.x Conversion With coremltools 3
PyTorch Conversion Using ONNX
ONNX Conversion Tips
Torch7 Conversion Tips
MXNet Conversion Tips
Troubleshooting the Conversion Process
Writing Your Own Converter
NeuralNetworkBuilder
Model Training Tips
- Part 3: Examining Models
Viewing Models With Netron
Viewing Models With visualize_spec
The mlmodel File Format
Dynamic Tensor Shapes
Using the Spec to Edit Models
Looking Inside an mlmodel
Verifying the Conversion is Successful
Looking at Intermediate Layer Outputs
Checking the Layer Output Shapes
The mlmodel as a Big Text File
- Part 4: Model Surgery
Filling in the Metadata
Changing the Image Preprocessing Options
Using a Different Scale for Each Color Channel
Saving the Weights as 16-bit Floats
Quantizing the Weights
Changing the Input Type to Image
Outputting an Image Instead of a MultiArray
Outputting Floats Instead of Doubles
Tidying up MultiArray Shapes
Renaming Inputs and Outputs
Inserting a New Layer
Changing an Existing Layer
Deleting a Layer
Example: Cleaning Up a Converted Model (DeepLab v3+)
Replacing the Class Names of a Classifier
- Part 5: Inside the App
Understanding the Xcode-generated File
mlmodelc
Running the Core ML Compiler Manually
Downloading and Compiling Models on the Device
Running the Model on the CPU
The Neural Engine
CPU, GPU, or Neural Engine?
Inspecting the Model at Runtime
Making Sure the Input is Correct
Working With CVPixelBuffer
Using CGImage or Image Files Instead of CVPixelBuffer
Working With MLMultiArray
Reshaping an MLMultiArray
Transposing an MLMultiArray
Converting MLMultiArray to an Image
Converting from UIImage to MLMultiArray
Computing the Argmax
Translating Class Labels
- Part 6: Advanced Topics
Making Multiple Predictions at Once With Batches
Size Flexibility
Using the MLModel API
Vision FeaturePrint
Using Sequences
Creating Your Own Custom Layers
Creating Your Own Custom Models
Building Pipeline Models
Linked Models
Control Flow in Graphs
Working With Video
MobileNetV2 + SSDLite Example
Using Protobuf Without coremltools
Encrypting Models
Performance Tips
- Part 7: On-device Personalization
What is on-device personalization?
Making a Model Updatable
Training a Neural Network
k-Nearest Neighbors