One Logo Pool Ball
CoreML · IOS API REFERENCE

MLModel

class · iOS 11.0+ · SDK 27.1

class MLModel

Members (24)

static · iOS 16.0+

compileModel

TypeScript
static compileModelAt(modelURL: string): Promise<string>
Swift declaration
class func compileModel(at modelURL: URL) async throws -> URL
static · iOS 11.0+ · Deprecated in iOS 100000.0

compileModel

TypeScript
static compileModelAt10374(modelURL: string): string
Swift declaration
class func compileModel(at modelURL: URL) throws -> URL
static · iOS 16.0+

load

TypeScript
static loadConfigurationCompletionHandler(asset: MLModelAsset, configuration: MLModelConfiguration, handler: ((arg0: (MLModel) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
class func load(asset: MLModelAsset, configuration: MLModelConfiguration) async throws -> MLModel
init · iOS 12.0+

init

TypeScript
static initContentsOfConfiguration(url: string, configuration: MLModelConfiguration): MLModel
Swift declaration
convenience init(contentsOf url: URL, configuration: MLModelConfiguration) throws
init · iOS 11.0+

init

TypeScript
static initContentsOf(url: string): MLModel
Swift declaration
convenience init(contentsOf url: URL) throws
method · iOS 13.0+

parameterValue

TypeScript
parameterValue(key: MLParameterKey): unknown
Swift declaration
func parameterValue(for key: MLParameterKey) throws -> Any
method · iOS 11.0+

prediction

TypeScript
predictionFrom(input: SDKHandle): SDKHandle
Swift declaration
func prediction(from input: any MLFeatureProvider) throws -> any MLFeatureProvider
method · iOS 11.0+

prediction

TypeScript
predictionFromOptions(input: SDKHandle, options: MLPredictionOptions): SDKHandle
Swift declaration
func prediction(from input: any MLFeatureProvider, options: MLPredictionOptions) throws -> any MLFeatureProvider
method · iOS 18.0+

prediction

TypeScript
predictionFromUsing(inputFeatures: SDKHandle, state: MLState): SDKHandle
Swift declaration
func prediction(from inputFeatures: any MLFeatureProvider, using state: MLState) throws -> any MLFeatureProvider
method · iOS 18.0+

prediction

TypeScript
predictionFromUsingOptions(inputFeatures: SDKHandle, state: MLState, options: MLPredictionOptions): SDKHandle
Swift declaration
func prediction(from inputFeatures: any MLFeatureProvider, using state: MLState, options: MLPredictionOptions) throws -> any MLFeatureProvider
method · iOS 12.0+

predictions

TypeScript
predictionsFromBatch(inputBatch: SDKHandle): SDKHandle
Swift declaration
func predictions(fromBatch inputBatch: any MLBatchProvider) throws -> any MLBatchProvider
method · iOS 12.0+

predictions

TypeScript
predictionsFromOptions(inputBatch: SDKHandle, options: MLPredictionOptions): SDKHandle
Swift declaration
func predictions(from inputBatch: any MLBatchProvider, options: MLPredictionOptions) throws -> any MLBatchProvider
get · iOS 12.0+

configuration

TypeScript
get configuration(): MLModelConfiguration
Swift declaration
var configuration: MLModelConfiguration { get }
get · iOS 11.0+

modelDescription

TypeScript
get modelDescription(): MLModelDescription
Swift declaration
var modelDescription: MLModelDescription { get }
method · iOS 18.0+

prediction

TypeScript
predictionFromUsingOptions91549(input: SDKHandle, state: MLState, options?: MLPredictionOptions): Promise<SDKHandle>
Swift declaration
func prediction(from input: any MLFeatureProvider, using state: MLState, options: MLPredictionOptions = MLPredictionOptions()) async throws -> any MLFeatureProvider

Run a stateful prediction on a model asynchronously. ```swift let state = model.newState() let prediction = try await model.prediction(from: inputFeatures, using: state) ``` - Parameters: - input: The input features to make a prediction from. - state: The state. - options: Optional prediction options to modify how the prediction is run - Returns: The output from the prediction.

method · iOS 18.0+

prediction

TypeScript
predictionFromUsing53525(inputs: Record<string, MLTensor>, state: MLState): Promise<Record<string, MLTensor>>
Swift declaration
func prediction(from inputs: [String : MLTensor], using state: MLState) async throws -> [String : MLTensor]

Run a stateful prediction on a model. This method requires all inputs and outputs to be multidimensional arrays. If your model doesn't satisfy this requirement, materialize the tensor inputs to `MLShapedArray` values to create feature values for each, for example: ```swift let shapedArray = await tensor.shapedArray(of: Float.self) let inputFeatures = try MLDictionaryFeatureProvider(dictionary: [ "x": MLFeatureValue(shapedArray: shapedArray), // Other non-multidimensional array inputs ]) let state = model.newState() let prediction = try await model.prediction(from: inputFeatures, using: state) ``` - Parameters: - inputs: The named input, or inputs, to make a prediction from. - state: The state. - Returns: The output, or outputs, from the prediction.

method · iOS 17.0+

prediction

TypeScript
predictionFromOptions37517(input: SDKHandle, options?: MLPredictionOptions): Promise<SDKHandle>
Swift declaration
func prediction(from input: any MLFeatureProvider, options: MLPredictionOptions = MLPredictionOptions()) async throws -> any MLFeatureProvider

Run a prediction on a model asynchronously. - Parameter input: The input features to make a prediction from. - Parameter options: Optional prediction options to modify how the prediction is run - Returns: The output from the prediction.

method · iOS 18.0+

prediction

TypeScript
predictionFrom13483(inputs: Record<string, MLTensor>): Promise<Record<string, MLTensor>>
Swift declaration
func prediction(from inputs: [String : MLTensor]) async throws -> [String : MLTensor]

Run a prediction on a model. This method requires all inputs and outputs to be multidimensional arrays. If your model doesn't satisfy this requirement, materialize the tensor inputs to `MLShapedArray` values to create feature values for each, for example: ```swift let shapedArray = await tensor.shapedArray(of: Float.self) let inputFeatures = try MLDictionaryFeatureProvider(dictionary: [ "x": MLFeatureValue(shapedArray: shapedArray), // Other non-multidimensional array inputs ]) let prediction = try await model.prediction(from: inputFeatures) ``` - Parameter inputs: The named input, or inputs, to make a prediction from. - Returns: The output, or outputs, from the prediction.

static · iOS 16.0+

compileModel

TypeScript
static compileModelAt94960(url: string): Promise<string>
Swift declaration
class func compileModel(at url: URL) async throws -> URL

Using Swift 'async' idiom.

static · iOS 16.0+

compileModel

TypeScript
static compileModelAtCompletionHandler(url: string, handler: ((arg0: SDKHandle) => void)): void
Swift declaration
class func compileModel(at url: URL, completionHandler handler: @escaping (Result<URL, any Error>) -> Void)

Compile a .mlmodel asynchronously given its on-disk location. Model compilation may take a considerable amount of time. Use this factory method especially when the caller is on the main thread. - Parameter url: Location of the .mlmodel file. - Parameter handler: When the model compilation completes successfully the completion handler is invoked with a valid URL to the compiled .mlmodelc directory. On failure the completion handler is invoked with an NSError object. The model is compiled to a temporary location on disk. You must move the compiled model to a permanent location if you wish to keep it.

get · iOS 17.0+

availableComputeDevices

TypeScript
static get availableComputeDevices(): Array<MLComputeDevice>
Swift declaration
static var availableComputeDevices: [MLComputeDevice] { get }

The list of available compute devices for CoreML. Use the method to get the list of compute devices that MLModel's prediction can use. The hardware may have other compute devices that are not available to CoreML. Use `MLComputeDevice.allComputeDevices` to get the complete list.

static · iOS 14.0+

load

TypeScript
static loadContentsOfConfigurationCompletionHandler(url: string, configuration: MLModelConfiguration, handler: ((arg0: SDKHandle) => void)): void
Swift declaration
class func load(contentsOf url: URL, configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Result<MLModel, any Error>) -> Void)

Construct a model asynchronously given the location of its on-disk representation and configuration. Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread. - Parameter url: Location of its on-disk representation (.mlmodelc directory). - Parameter configuration: Configuration The model configuration - Parameter handler: When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.

static · iOS 15.0+

load

TypeScript
static loadContentsOfConfiguration(url: string, configuration?: MLModelConfiguration): Promise<MLModel>
Swift declaration
class func load(contentsOf url: URL, configuration: MLModelConfiguration = MLModelConfiguration()) async throws -> MLModel

Construct a model asynchronously given the location of its on-disk representation and configuration. Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread. - Parameter url: Location of its on-disk representation (.mlmodelc directory). - Parameter configuration: Configuration The model configuration - Returns: A constructed MLModel object.

method · iOS 18.0+

makeState

TypeScript
makeState(): MLState
Swift declaration
func makeState() -> MLState

Creates a new state object. Core ML framework will allocate the state buffers declared in the model. The allocated state buffers are initialized to zeros. To initialize with different values, use `.withMultiArray(for:)` to get the mutable `MLMultiArray`-view to the state buffer. ```swift // Create state that contains two state buffers: s1 and s2. // Then, initialize s1 to 1.0 and s2 to 2.0. let state = model.makeState() state.withMultiArray(for: "s1") { stateMultiArray in stateMultiArray[0] = 1.0 } state.withMultiArray(for: "s2") { stateMultiArray in stateMultiArray[0] = 2.0 } ```

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

MLModel.init()

inherited init: cannot prove legal (class declares 4 custom initializers)

All CoreML types →