LearningModelSession 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
用于评估机器学习模型。
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
- 继承
- 属性
- 实现
Windows 要求
设备系列 |
Windows 10, version 1809 (在 10.0.17763.0 中引入)
|
API contract |
Windows.AI.MachineLearning.MachineLearningContract (在 v1.0 中引入)
|
示例
以下示例加载模型并使用它创建评估会话。
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;
}
}
注解
Windows Server
若要在 Windows Server 上使用此 API,必须使用具有桌面体验的 Windows Server 2019。
线程安全
此 API 是线程安全的。
版本历史记录
Windows 版本 | SDK 版本 | 已添加值 |
---|---|---|
1903 | 18362 | LearningModelSession (LearningModel,LearningModelDevice,LearningModelSessionOptions) |
构造函数
LearningModelSession(LearningModel) |
使用默认设备创建会话。 |
LearningModelSession(LearningModel, LearningModelDevice) |
使用指定的设备创建会话。 |
LearningModelSession(LearningModel, LearningModelDevice, LearningModelSessionOptions) |
使用指定的设备和其他推理选项创建会话。 |
属性
Device |
返回会话的评估设备。 |
EvaluationProperties |
控制模型评估的属性集。 |
Model |
返回此会话的训练机器学习模型。 |
方法
Close() |
关闭当前 LearningModelSession。 |
Dispose() |
执行与释放或重置非托管资源关联的应用程序定义的任务。 |
Evaluate(LearningModelBinding, String) |
使用 绑定中绑定的特征值评估机器学习模型。 |
EvaluateAsync(LearningModelBinding, String) |
使用 绑定中已绑定的特征值异步评估机器学习模型。 |
EvaluateFeatures(IMap<String,Object>, String) |
使用 特征中的特征值评估机器学习模型。 |
EvaluateFeaturesAsync(IMap<String,Object>, String) |
使用 特征中的特征值异步评估机器学习模型。 |