LearningModelSession 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.
Used to evaluate machine learning models.
public ref class LearningModelSession sealed : IClosable
/// [Windows.Foundation.Metadata.Activatable(Windows.AI.MachineLearning.ILearningModelSessionFactory, 65536, "Windows.AI.MachineLearning.MachineLearningContract")]
/// [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 LearningModelSession final : IClosable
/// [Windows.Foundation.Metadata.Activatable(Windows.AI.MachineLearning.ILearningModelSessionFactory, 65536, "Windows.AI.MachineLearning.MachineLearningContract")]
/// [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)]
/// [Windows.Foundation.Metadata.Activatable(Windows.AI.MachineLearning.ILearningModelSessionFactory2, 131072, "Windows.AI.MachineLearning.MachineLearningContract")]
class LearningModelSession final : IClosable
[Windows.Foundation.Metadata.Activatable(typeof(Windows.AI.MachineLearning.ILearningModelSessionFactory), 65536, "Windows.AI.MachineLearning.MachineLearningContract")]
[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 LearningModelSession : System.IDisposable
[Windows.Foundation.Metadata.Activatable(typeof(Windows.AI.MachineLearning.ILearningModelSessionFactory), 65536, "Windows.AI.MachineLearning.MachineLearningContract")]
[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)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.AI.MachineLearning.ILearningModelSessionFactory2), 131072, "Windows.AI.MachineLearning.MachineLearningContract")]
public sealed class LearningModelSession : System.IDisposable
function LearningModelSession(model, deviceToRunOn)
function LearningModelSession(model, deviceToRunOn, learningModelSessionOptions)
Public NotInheritable Class LearningModelSession
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
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.
Version history
Windows version | SDK version | Value added |
---|---|---|
1903 | 18362 | LearningModelSession(LearningModel,LearningModelDevice,LearningModelSessionOptions) |
Constructors
LearningModelSession(LearningModel) |
Creates a session using the default device. |
LearningModelSession(LearningModel, LearningModelDevice) |
Creates a session using the specified device. |
LearningModelSession(LearningModel, LearningModelDevice, LearningModelSessionOptions) |
Creates a session using the specified device and additional inference options. |
Properties
Device |
Returns the session's evaluation device. |
EvaluationProperties |
Set of properties that control model evaluation. |
Model |
Returns the trained machine learning model for this session. |
Methods
Close() |
Closes the current LearningModelSession. |
Dispose() |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
Evaluate(LearningModelBinding, String) |
Evaluate the machine learning model using the feature values bound in bindings. |
EvaluateAsync(LearningModelBinding, String) |
Asynchronously evaluate the machine learning model using the feature values already bound in bindings. |
EvaluateFeatures(IMap<String,Object>, String) |
Evaluate the machine learning model using the feature values in features. |
EvaluateFeaturesAsync(IMap<String,Object>, String) |
Asynchronously evaluate the machine learning model using the feature values in features. |