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 と evalaute を作成します。

Windows Server

Windows Server でこの API を使用するには、Windows Server 2019 デスクトップ エクスペリエンスを使用する必要があります。

スレッド セーフ

この API はスレッド セーフです。

プロパティ

Author

モデル作成者の名前。

Description

モデルの説明。

Domain

モデルのドメイン。

InputFeatures

モデルの入力機能の一覧。

Metadata

ONNX モデルからの生 <の文字列、文字列> メタデータ。

Name

モデルの名前。

OutputFeatures

モデルの出力機能の一覧。

Version

モデルのバージョン。

メソッド

Close()

メモリ内 ONNX モデルを解放します。 これを呼び出した後は、それ以上 LearningModelSession オブジェクトを 作成することはできません。

Dispose()

アンマネージ リソースの解放またはリセットに関連付けられているアプリケーション定義のタスクを実行します。

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 モデルを非同期的に読み込みます。

適用対象

こちらもご覧ください