Core ML Survival Guide
This book is 90% complete
Last updated on 2018-12-09
About the Book
Core ML has made it easier than ever to add machine learning to your iOS and macOS apps. Drag-and-drop an mlmodel file into your Xcode project, literally write two lines of code, and you’re done!
There are lots of tutorials that show how to get started with Core ML, but they only cover the very basics.
- What if you want to do something more advanced?
- What if you run into problems?
- Where do you get Core ML models to begin with anyway?
Core ML may appear easy-to-use at first — but if you want to go beyond the basics, the learning curve suddenly becomes very steep. My goal with this book is to make the advanced features of Core ML accessible to everyone too.
I do machine learning on mobile for a living and I’ve been working with Core ML since it first came out. Every time I ran into a problem, I put the solution into a notes file. From posts on Stack Overflow, the Apple Developer Forums, and emails I receive from readers of my blog, it’s clear that other people are running into the same problems. So I collected my notes, cleaned them up, and put them into this book.
The Core ML Survival Guide contains pretty much everything I know about Core ML. With this book I hope to save you some time from having to figure out this stuff by yourself.
What you’ll learn:
- How to best convert your models to Core ML. One of the biggest showstoppers happens right at the beginning: you’ve trained a model but the Core ML conversion fails. This book explains what to pay attention to when you’re training your models, and how you can convert troublesome models to Core ML anyway by writing your own converter.
- The mlmodel file format and what Core ML’s possibilities and limitations are. Understanding the internals of mlmodel files is useful to verify the model conversion was successful — but also for knowing how to design and train your models in the first place.
- Model surgery. Lots of advice on how to fix problems with your mlmodel files and how to get the leanest — and fastest — Core ML models.
- Tips for running the app on the device. It’s pretty easy to make predictions with Core ML once you have a model, but there are still some gotchas to watch out for. For example, you’ll want to verify the model really does what you expect it to! Also: how to make effective use of the new Neural Engine.
- Working with CVPixelBuffer and MLMultiArray. When your model does more than just classification, you’ll need to understand how to read and write MLMultiArray objects. This part of the book shows effective methods for making MLMultiArray do what you want.
- Advanced topics: Custom layers, custom models, building pipelines, working with video, using sequences, and much more!
This book has over 60 chapters and is packed with tips and tricks. As I learn more about Core ML myself, I’ll keep updating the book so you’ll always have access to the most up-to-date knowledge about Core ML.
If Core ML is giving you trouble — or if you want to make the most out your Core ML models — then the Core ML Survival Guide is for you!
- About the Author
- 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
- Where to Get mlmodels?
- Create ML: The Easiest Way to Train
- Turi Create — it’s Like Create ML but in Python
Part 2: Converting Models
- Image Preprocessing
- Keras Conversion Tips
- Caffe Conversion Tips
- TensorFlow Conversion Tips
- PyTorch Conversion Tips
- MXNet Conversion Tips
- ONNX Conversion Tips
- Writing Your Own Converter
- Model Training Tips
Part 3: Examining Models
- Viewing Models With Netron
- Viewing Models With visualize_spec
- The mlmodel File Format
- 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
- Changing the Image Preprocessing Options
- Using a Different Scale for Each Color Channel
- Saving the Weights as 16-bit Floats
- Quantizing the Weights
- Outputting Floats Instead of Doubles
- Outputting an Image Instead of a MultiArray
- Tidying up MultiArray Shapes
- Inserting a New Layer
- Changing an Existing Layer
- Cleaning Up a Converted Model
- Replacing the Class Names of a Classifier
Part 5: Inside the App
- Understanding the Xcode-generated File
- 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
- Working With MLMultiArray
- Reshaping an MLMultiArray
- Transposing an MLMultiArray
- Converting MLMultiArray to an Image
- 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 (Turi Create YOLO Example)
- Doing Your Own Post-Processing Inside the Model (SSDLite Example)
- Working With Video
- Using Protobuf Without coremltools
- Encrypting Models
- Performance Tips
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...