MLFeatureProvider
An interface that represents a collection of values for either a model’s input or its output.
Declaration
protocol MLFeatureProviderOverview
Use MLFeatureProvider to customize the way your app gets data to and from your model when the model’s dynamically generated interface doesn’t meet your app’s needs.
Consider adopting this protocol in your data source if any of the following apply:
Your data is collected asynchronously.
Using the autogenerated interface leads to copying excessive amounts of data.
Your data source is otherwise complicated.
The interface is mainly an accessor for MLFeatureValue instances, making it straightforward to implement. Adopting this protocol allows you to integrate your data directly with MLModel, which means the model can query your data sources without constructing a separate input instance.
To customize your app’s interaction with a model:
Adopt the
MLFeatureProviderprotocol in a class or structure so that the model can query it for input feature values via featureValue(for:).Pass your app’s
MLFeatureProviderto yourMLModelwith prediction(from:) or prediction(from:options:).Use the
MLFeatureProviderreturned from aprediction(from:)method to get the output feature values for that prediction.