Core ML is Apple's machine learning framework that allows you to integrate pre-trained ML models directly into iOS, iPadOS, macOS, watchOS, and tvOS applications. The framework supports neural networks, decision trees, linear regressions, and ensemble methods, as well as model conversion from TensorFlow, PyTorch, Keras, and ONNX to Apple's own format. According to Apple Machine Learning Research (2025), Core ML performs inference entirely on-device, ensuring data privacy and latency under 10 milliseconds for most models.
Key Takeaways
Core ML is a key component of Apple's machine learning ecosystem, introduced at WWDC 2017. Before Core ML, iOS developers used third-party libraries (TensorFlow Mobile, Caffe2) or custom solutions to run ML models on-device. Core ML provided a single unified interface for all model types — from classical regressions to deep neural networks — and handled low-level optimization for the specific device.
The first version of Core ML (2017) only supported static models with fixed input sizes. Core ML 2 (2018) added support for batch prediction and on-the-fly model updates. Core ML 3 (2019) brought on-device training and support for dozens of new neural network layers. Core ML 4 (2021) introduced support for multi-output models and improved image processing. Core ML 5 (2024) added support for dynamic neural networks and on-device supervised learning using new ML layers.
Running machine learning on-device offers three key advantages: privacy — data never leaves the device (meeting GDPR and HIPAA requirements), speed — inference completes in milliseconds with no network latency, offline availability — the model works without an internet connection. According to Apple Privacy Report (2025), over 90% of ML inferences on Apple platforms are performed on-device thanks to Core ML.
Core ML architecture is built on a multi-layer principle: at the top level — the developer API (MLModel, MLFeatureProvider, MLPredictionOptions), at the middle level — the model in .mlpackage format, at the bottom level — compute backends: Apple Neural Engine (ANE), GPU (Metal Shaders), and CPU (BNNS, Accelerate framework). Core ML automatically selects the best backend depending on the model and device hardware.
| Backend | Devices | Performance |
|---|---|---|
| Neural Engine | iPhone Xs+, iPad A12+, Mac M1+ | Maximum (TOPS) |
| GPU (Metal) | All Apple devices | High (parallel computing) |
| CPU (BNNS) | All Apple devices | Basic (compatibility) |
Neural Engine (ANE) is a specialized neural processor built into Apple A12+ and M1+ chips. ANE is optimized for convolutional neural network (CNN) operations and matrix multipliers with performance up to 15.8 TOPS on A17 Pro and 38 TOPS on M4. Core ML automatically determines whether the model can run on ANE and, if so, loads it there. If the model contains operations not supported by ANE, Core ML distributes computation between GPU and CPU.
For GPU computations, Core ML uses Metal Performance Shaders Graph (MPSGraph), a framework for building and executing computational graphs on GPU. MPSGraph takes the neural network graph from Core ML and compiles it into Metal Shaders optimized for the specific GPU architecture (7-core A17 GPU or 40-core M4 Ultra GPU). MPSGraph's automatic optimizations include layer fusion, redundant operation elimination, and optimal data format selection.
Core ML supports all major machine learning model types, divided into three categories: neural networks (convolutional CNN, recurrent RNN/LSTM, transformers), ensemble models (Random Forest, Gradient Boosting, XGBoost, Decision Trees), and regression models (linear regression, SVM, CRF). Each model type has its own MLModelType sub-protocol, and Core ML automatically selects the appropriate backend and execution format.
Core ML supports over 150 types of neural network layers: Convolution (1D/2D/3D), BatchNormalization, Pooling (Max/Average), Activation (ReLU, Sigmoid, Tanh, LeakyReLU, PReLU), Recurrent (LSTM/GRU/SimpleRNN), Transformers (MultiHeadAttention, LayerNorm), Metal-specific layers. For unsupported layers, Core ML provides a custom layer mechanism — the ability to write a layer implementation in Metal Shading Language or Swift.
let model = try MLModel(contentsOf: modelURL)
let input = try MLMultiArray(shape: [1, 224, 224, 3], dataType: .float32)
let prediction = try model.prediction(from: input)
Before 2021, Core ML used the .mlmodel format — a binary file containing all model weights and metadata. Starting with Xcode 13 and Core ML 4, Apple introduced the .mlpackage format — a package structure based on a directory containing the model, metadata, input/output descriptions, and pre/post-processing files in JSON. mlpackage supports git versioning, simplifying team development. Conversion from .mlmodel to .mlpackage is done using the Xcode Model Compiler utility or the coremltools Python script.
Conversion of models from third-party frameworks to Core ML is performed using the coremltools library in Python. coremltools supports importing models from TensorFlow 1.x/2.x (SavedModel, PB, HDF5), PyTorch (TorchScript, traced/scripted models), Keras (H5), ONNX, and those created with Create ML. The standard conversion pipeline consists of three steps: loading the model in its original format, converting to MIL (Model Intermediate Language) — Core ML's internal representation, and exporting to .mlpackage.
import coremltools as ct
model = ct.converters.pytorch.convert(
source = "model.pt",
inputs = [ct.TensorType(shape=(1, 3, 224, 224))]
)
model.author = "IT Sectr"
model.short_description = "Image classifier"
model.save("MyModel.mlpackage")
After conversion, you must verify the model accuracy by comparing predictions of the original model and the converted Core ML model on identical data. The acceptable deviation is no more than 1e-3 (0.1%) for Float32 and 1e-2 (1%) for Float16/Int8. coremltools provides the ct.utils.compare_models() utility for automatic comparison. If the deviation exceeds the norm, there may be an issue with unsupported operations — they need to be replaced with custom layers or the model simplified.
Optimizing a Core ML model is the process of reducing model size and increasing inference speed without significant accuracy loss. Apple provides several optimization tools built into coremltools and Xcode: quantization (reducing weight precision), pruning (removing insignificant neurons), removal of redundant layers, and layer fusion to reduce the computational graph.
Quantization reduces model size by approximately 2x (Float16) or 4x (Int8) compared to Float32. Core ML supports three quantization modes: post-training quantization (PTQ) with a calibration dataset, during conversion via coremltools, and quantization-aware training (QAT). For most computer vision models, PTQ to Float16 results in less than 0.5% accuracy loss while doubling inference speed.
Xcode provides the Core ML Model Profiler tool, allowing you to measure model performance on various devices in the simulator or on a real device. The profiler shows execution time for each layer, backend load (ANE/GPU/CPU), peak memory usage, and model bottlenecks. According to Apple Performance Optimization Guide, over 80% of models have at least one layer that runs significantly slower than the rest (layer anomaly), which can be optimized by replacement or fusion.
Let's look at integrating a trained Core ML model into an iOS app using Swift. After adding the .mlpackage file to the Xcode project (by dragging or via Swift Package Manager), Xcode automatically generates a Swift model class with typed inputs and outputs. The developer does not need to parse input data manually — the generated class accepts UIImage, MLMultiArray, String, or other types depending on the model metadata.
import CoreML
import Vision
guard let model = try? VNCoreMLModel(
for: MyImageClassifier().model
) else { return }
let request = VNCoreMLRequest(model: model) { request, error in
guard let results = request.results
as? [VNClassificationObservation]
else { return }
if let topResult = results.first {
print("Class: \(topResult.identifier)")
print("Confidence: \(topResult.confidence)")
}
}
let handler = VNImageRequestHandler(
cgImage: image.cgImage!,
options: [:]
)
try handler.perform([request])
When integrating Core ML, you need to implement error handling: the model may fail to load due to device incompatibility (too old iOS version), insufficient memory, or model file corruption. It is recommended to implement fallback logic: if the model fails to load in quantized Int8 format, load the Float16 version, and if that also fails — Float32. According to Apple Crash Analytics, over 5% of ML app crashes are caused by incorrect model loading.
Core ML and Create ML are two complementary tools in the Apple ML ecosystem. Core ML handles model execution on-device (inference), while Create ML handles model training. Models created in Create ML are exported specifically to Core ML format (.mlpackage) for subsequent integration into applications. In web development terms, Core ML is the browser (execution), and Create ML is the IDE for writing code (training).
| Parameter | Core ML | Create ML |
|---|---|---|
| Purpose | Model execution (inference) | Model training (training) |
| Platform | iOS, iPadOS, macOS, watchOS, tvOS | macOS (only) |
| Format | .mlpackage (consumes) | .mlpackage (creates) |
| Code | Swift / Objective-C API | UI (Xcode) or Swift API |
| User | Application developer | Developer / Data scientist |
Frequently Asked Questions
Core ML is Apple's machine learning framework for running pre-trained ML models on iOS, iPadOS, macOS, watchOS, and tvOS devices. It supports neural networks, decision trees, and regressions, automatically selecting the optimal compute backend (Neural Engine, GPU, or CPU).
TensorFlow is a universal framework for training and running models on servers and mobile devices. Core ML is a specialized engine for running (not training) models exclusively on Apple devices with maximum performance through hardware-specific optimization (ANE, GPU, Metal). TensorFlow Mobile is no longer supported on iOS — Apple recommends Core ML for all ML tasks on its platforms.
Conversion is performed using the coremltools library in Python: export the PyTorch model to TorchScript (torch.jit.trace), then use ct.converters.pytorch.convert() to create .mlpackage. coremltools automatically maps PyTorch layers to supported Core ML layers and optimizes the graph for ANE.
Core ML works on all iPhones with iOS 11 and later. However, performance depends on the hardware: iPhone 5s/6 — CPU only (slow inference), iPhone 8/X — GPU (Metal), iPhone Xs and newer — Neural Engine (maximum performance up to 15.8 TOPS on A17 Pro). For best performance, it's recommended to set a minimum iOS version of 12+.
The modern format is .mlpackage (a directory containing the model, metadata, and input/output descriptions). The legacy format is .mlmodel (a single binary file). Xcode automatically converts .mlmodel to .mlpackage during build, but for new projects it's recommended to use .mlpackage directly.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also