LearningModel 類別

定義

表示定型的機器學習模型。

public ref class LearningModel sealed : IClosable
/// [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 LearningModel final : IClosable
[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 LearningModel : System.IDisposable
Public NotInheritable Class LearningModel
Implements IDisposable
繼承
Object Platform::Object IInspectable LearningModel
屬性
實作

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 ML 互動的主要物件。 您可以使用它來載入、系結及評估定型的 ONNX 模型:

  1. 使用其中一個 Load* 建構函式 載入模型。
  2. 列舉 InputFeaturesOutputFeatures ,並系結至您的模型。
  3. 建立 LearningModelSession 和規避。

Windows Server

若要在 Windows Server 上使用此 API,您必須搭配桌面體驗使用 Windows Server 2019。

執行緒安全

此 API 是安全線程。

屬性

Author

模型作者的名稱。

Description

模型的描述。

Domain

模型的領域。

InputFeatures

模型的輸入特徵清單。

Metadata

ONNX 模型中的原始 < 字串、字串 > 中繼資料。

Name

模型的名稱。

OutputFeatures

模型的輸出功能清單。

Version

模型的版本。

方法

Close()

釋放記憶體內部 ONNX 模型。 呼叫此專案之後,您無法再建立任何 LearningModelSession 物件。

Dispose()

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

LoadFromFilePath(String)

從磁片上的檔案載入 ONNX 模型。

LoadFromFilePath(String, ILearningModelOperatorProvider)

從磁片上的檔案載入 ONNX 模型。

LoadFromStorageFileAsync(IStorageFile)

以非同步方式從 IStorageFile 載入 ONNX 模型。

LoadFromStorageFileAsync(IStorageFile, ILearningModelOperatorProvider)

以非同步方式從 IStorageFile 載入 ONNX 模型。

LoadFromStream(IRandomAccessStreamReference)

從資料流程載入 ONNX 模型。

LoadFromStream(IRandomAccessStreamReference, ILearningModelOperatorProvider)

從資料流程載入 ONNX 模型。

LoadFromStreamAsync(IRandomAccessStreamReference)

以非同步方式從資料流程載入 ONNX 模型。

LoadFromStreamAsync(IRandomAccessStreamReference, ILearningModelOperatorProvider)

以非同步方式從資料流程載入 ONNX 模型。

適用於

另請參閱