Introduction
Core ML models are the trained models that apps run on Apple devices through
Core ML, Apple’s
machine learning framework, introduced in 2017. Developers convert a model from PyTorch,
TensorFlow or another framework with Apple’s coremltools, add the file to an Xcode
project, and Xcode compiles it into an .mlmodelc folder that ships inside the
app.
There are two forms. An .mlmodel is a single file. An
.mlpackage, added in 2021 for the newer ML Program model type, is a folder
that keeps the weights in a separate file so large models are easier to handle.
Structure
An .mlmodel file is one Protocol
Buffers message of type Model, defined in the
Model.proto schema that Apple publishes with coremltools. It has a
specificationVersion, a description of the inputs, outputs and
metadata such as author and licence, and exactly one model body: a neural network, an ML
Program, a pipeline of other models, a tree ensemble, a linear model and so on.
An .mlpackage is a folder (shown as one file on a Mac) with a
Manifest.json and a Data/com.apple.CoreML/ folder holding the
model.mlmodel specification and a weights/ folder with the
weights. The Model message page lists the
fields, model types and specification versions.
Not described
The reference follows the .proto files of Apple's coremltools repository.
The layer parameter messages, the standalone model messages, the blob v2 weight file and the operation names of the ML Program opsets are now on the model page.
Known, not yet covered
- Reference: the inputs, outputs, attributes and type constraints of each ML Program operation (they are in the docstrings of the Python classes, which were not copied), and the semantic notes in the layer messages' comments beyond those quoted (shapes and rounding rules of each layer).
- Viewer: not re-audited in this pass.
Unknown
- Reference: the byte layout of
modelParameterDatain TextClassifier, WordTagger, Gazetteer and WordEmbedding (an Apple Natural Language framework format; the proto calls it learned parameters and gives no layout), and the contents of aSerializedModel, which Model.proto calls private and subject to change without notice.
Links
Software
Developers
- coremltools – Apple’s package for converting, editing and checking models (Python)
- Core ML – the framework apps use to run models (Swift, Objective-C)
Reference
- Core ML Model Format Specification – Apple’s description of the model message and its types