共用方式為


LearningModelSession 類別

定義

用來評估機器學習模型。

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
繼承
Object Platform::Object IInspectable LearningModelSession
屬性
實作

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()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

Evaluate(LearningModelBinding, String)

使用系 結中的特徵值來評估機器學習模型。

EvaluateAsync(LearningModelBinding, String)

使用系 結中已系結的功能值,以非同步方式評估機器學習模型。

EvaluateFeatures(IMap<String,Object>, String)

使用 特徵中的特徵值來評估機器學習模型。

EvaluateFeaturesAsync(IMap<String,Object>, String)

使用 特徵中的特徵值,以非同步方式評估機器學習模型。

適用於

另請參閱