Deep Dojo

Compiling Core ML Models on Device

Camilla Dahlstrøm dives under the hood and reveals some dynamic details of Core ML.

“This post will have a look at the case where the developer wishes to update or insert a model into the application, but avoiding the process of recompiling the entire application. … Several approaches will be discussed, from Apple’s preferred method to less conventional tricks which trade speed and storage efficiency alike.”

Matthijs Hollemans dives into even greater detail.

On the surface, Core ML has the appearance of being fairly static. You bring a trained model file into your project and let Xcode turn it into a runtime solution when your app is built. The details, it turns out, are a bit more dynamic.

Some of these details have even made their way up to public API.

let compiledModelURL = try MLModel.compileModel(at: modelURL)
let model = FlowerClassifier(contentsOf: compiledModelURL)