Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 1.71 KB

learningmodel.md

File metadata and controls

58 lines (45 loc) · 1.71 KB
-api-id -api-type ms.custom
T:Windows.AI.MachineLearning.LearningModel
winrt class
RS5

Windows.AI.MachineLearning.LearningModel

-description

Represents a trained machine learning model.

-remarks

This is the main object you use to interact with Windows ML. You use it to load, bind, and evaluate trained ONNX models:

  1. Load the model using one of the Load* constructors.
  2. Enumerate the InputFeatures and OutputFeatures and bind to your model.
  3. 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.

-see-also

Windows ML, Windows ML samples (GitHub)

-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;
    }
}