Protocol

MLCustomModel

An interface that defines the behavior of a custom model.

Declaration

protocol MLCustomModel

Overview

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.

@objc(MyCustomModel)
class MyCustomModel: NSObject, MLCustomModel {
  ...
}

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

Topics

Creating the Model

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

Creates a custom model with the given description and parameters.

Required.

Making Predictions

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

Predicts output values from the given input features.

Required.

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

Predicts output values from the given batch of input features.

See Also

Customization

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.