Type Method

compileModel(at:)

Compiles a model on the device to update the model in your app.

Declaration

class func compileModel(at modelURL: URL) throws -> URL

Parameters

at

The local file path to your downloaded .mlmodel file.

Return Value

The local file path to the compiled model (the .mlmodelc file).

Discussion

The source .mlmodel file must be on the device. Pass the compiled model to init(contentsOf:) to initialize an MLModel instance.

Listing 1

Compiling a model file and creating an MLModel instance from the compiled version

let compiledUrl = try MLModel.compileModel(at: modelUrl)
let model = try MLModel(contentsOf: compiledUrl)

Compiling can be time consuming and shouldn't be done on the main thread.

See Downloading and Compiling a Model on the User's Device for more details.

See Also