LearningModel Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a trained machine learning model.
public ref class LearningModel sealed : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.AI.MachineLearning.MachineLearningContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class LearningModel final : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.AI.MachineLearning.MachineLearningContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class LearningModel : System.IDisposable
Public NotInheritable Class LearningModel
Implements IDisposable
- Inheritance
- Attributes
- Implements
Windows requirements
Device family |
Windows 10, version 1809 (introduced in 10.0.17763.0)
|
API contract |
Windows.AI.MachineLearning.MachineLearningContract (introduced in v1.0)
|
Examples
The following example loads a model and creates an evaluation session with it.
private async Task LoadModelAsync(string _modelFileName)
{
LearningModel _model;
LearningModelSession _session;
try
{
// Load and create the model
var modelFile =
await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/{_modelFileName}"));
_model = await LearningModel.LoadFromStorageFileAsync(modelFile);
// Create the evaluation session with the model
_session = new LearningModelSession(_model);
}
catch (Exception ex)
{
StatusBlock.Text = $"error: {ex.Message}";
_model = null;
}
}
Remarks
This is the main object you use to interact with Windows ML. You use it to load, bind, and evaluate trained ONNX models:
- Load the model using one of the Load* constructors.
- Enumerate the InputFeatures and OutputFeatures and bind to your model.
- Create a LearningModelSession and evalaute.
Windows Server
To use this API on Windows Server, you must use Windows Server 2019 with Desktop Experience.
Thread safety
This API is thread-safe.
Properties
Author |
The name of the model author. |
Description |
A description of the model. |
Domain |
The domain of the model. |
InputFeatures |
A list of the model's input features. |
Metadata |
The raw <string,string> metadata from the ONNX model. |
Name |
The name of the model. |
OutputFeatures |
A list of the model's output features. |
Version |
The version of the model. |
Methods
Close() |
Releases the in-memory ONNX model. After calling this, you cannot create any more LearningModelSession objects. |
Dispose() |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
LoadFromFilePath(String, ILearningModelOperatorProvider) |
Loads an ONNX model from a file on disk. |
LoadFromFilePath(String) |
Loads an ONNX model from a file on disk. |
LoadFromStorageFileAsync(IStorageFile, ILearningModelOperatorProvider) |
Loads an ONNX model from an IStorageFile asynchronously. |
LoadFromStorageFileAsync(IStorageFile) |
Loads an ONNX model from an IStorageFile asynchronously. |
LoadFromStream(IRandomAccessStreamReference, ILearningModelOperatorProvider) |
Loads an ONNX model from a stream. |
LoadFromStream(IRandomAccessStreamReference) |
Loads an ONNX model from a stream. |
LoadFromStreamAsync(IRandomAccessStreamReference, ILearningModelOperatorProvider) |
Loads an ONNX model from a stream asynchronously. |
LoadFromStreamAsync(IRandomAccessStreamReference) |
Loads an ONNX model from a stream asynchronously. |