An interface that defines the behavior of a custom model.


protocol MLCustomModel


To integrate your custom model with Core ML, adopt the MLCustomModel protocol in the implementation of your custom model. If you use a Swift class for your custom implementation, make it accessible to Core ML by using the @objc(name) attribute.

class MyCustomModel: NSObject, MLCustomModel {

This defines the Objective-C name for the class, which Core ML needs to access your custom class’s implementation.


Creating the Model

init(modelDescription: MLModelDescription, parameters: [String : Any])

Creates a custom model with the given description and parameters.


Making Predictions

func prediction(from: MLFeatureProvider, options: MLPredictionOptions) -> MLFeatureProvider

Predicts output values from the given input features.


func predictions(from: MLBatchProvider, options: MLPredictionOptions) -> MLBatchProvider

Predicts output values from the given batch of input features.

See Also


Integrating Custom Layers

Integrate custom neural network layers into your Core ML app.

Creating a Custom Layer

Make your own custom layer for Core ML models.

protocol MLCustomLayer

An interface that defines the behavior of a custom layer in your neural network model.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software