-api-id | -api-type | ms.custom |
---|---|---|
M:Windows.AI.MachineLearning.LearningModelSession.#ctor(Windows.AI.MachineLearning.LearningModel) |
winrt method |
RS5 |
Creates a session using the default device.
The trained machine learning model for this session.
To use this API on Windows Server, you must use Windows Server 2019 with Desktop Experience.
This API is thread-safe.
The following example loads a model and creates an evaluation session with it.
private async Task LoadModelAsync(LearningModel _model, string _modelFileName, LearningModelSession _session)
{
// Only load the model one time.
if (_model != null) return;
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 and device.
_session = new LearningModelSession(_model);
}
catch (Exception ex)
{
StatusBlock.Text = $"error: {ex.Message}";
_model = null;
}
}