MLEdgeModel
represents an ML model that makes predictions on the local device. As such, it forms the basis for implementing Edge predictors in code.Predict
method which makes predictions on one or more MLEdgeFeature
instances. It returns a collection of MLEdgeFeature
instances, which can then be used with corresponding feature classes (MLArrayFeature
, MLAudioFeature
, and so on).Dispose
on the individual features, or on the returned feature collection to do so.MLEdgeModel
instances typically won't be used directly. Instead, they will be used through Edge Predictors, which are lightweight classes that can transform input data into the model's expected input features; and can transform the model's output features into easily usable types. Below are the general steps in implementing Edge predictors:IMLPredictor<TOutput>
interface. The predictor has a single generic type argument, TOutput
, which is a developer-friendly type that is returned when a prediction is made. For example, the MobileNetv2Predictor
predictor class which classifies an image uses a tuple for its output type:MLModel
instances, along with any other supplemental data needed to make predictions with the model(s). For example:MLModel
to an MLEdgeModel
and store a readonly reference to the edge model:Predict
method which accepts a params MLFeature[]
and returns a TOutput
, for example:Predict
method, the predictor should do three things:MLEdgeFeature
instances from input features. Creating an MLEdgeFeature
typically requires a corresponding MLFeatureType
which dictates any required pre-processing when creating the edge feature. You will typically use the model's input feature types for this purpose:IMLEdgeFeature
and check that the result of the cast is not null
.MLEdgeModel
:Dispose
method, because IMLPredictor
implements the IDisposable
interface. This method should be used to dispose any explicitly-managed resources used by the predictor. If a predictor does not have any explicitly-managed resources to dispose, then the predictor should hide the Dispose
method using interface hiding:Dispose
any models provided to it. This is the responsibility of the client.