Windows.AI.MachineLearning 名前空間

アプリで機械学習モデルを読み込み、特徴をバインドし、結果を評価できるようにします。

クラス

ImageFeatureDescriptor

モデルが期待するイメージのプロパティについて説明します。

ImageFeatureValue

モデルへの渡しに使用されるイメージのプロパティについて説明します。

LearningModel

トレーニング済みの機械学習モデルを表します。

LearningModelBinding

名前付き入力および出力機能に値をバインドするために使用されます。

LearningModelDevice

機械学習モデルの評価に使用されるデバイス。

LearningModelEvaluationResult

評価の結果を取得します。

LearningModelSession

機械学習モデルを評価するために使用されます。

LearningModelSessionOptions

LearningModelSession オブジェクトの作成時に使用される推論オプションについて説明します。

MapFeatureDescriptor

マップは、(キー、値) ペアのコレクションです。

SequenceFeatureDescriptor

シーケンスは要素の配列です。

TensorBoolean

ブール型のテンソル オブジェクト。

TensorDouble

64 ビット浮動小数点テンソル オブジェクト。

TensorFeatureDescriptor

テンソルは、値の多次元配列です。

TensorFloat

32 ビット浮動小数点テンソル オブジェクト。

TensorFloat16Bit

16 ビット浮動小数点テンソル オブジェクト。

TensorInt16Bit

16 ビット符号付き整数テンソル オブジェクト。

TensorInt32Bit

32 ビット符号付き整数テンソル オブジェクト。

TensorInt64Bit

64 ビット符号付き整数テンソル オブジェクト。

TensorInt8Bit

8 ビット符号付き整数テンソル オブジェクト。

TensorString

文字列テンソル オブジェクト。

TensorUInt16Bit

16 ビット符号なし整数テンソル オブジェクト。

TensorUInt32Bit

32 ビット符号なし整数テンソル オブジェクト。

TensorUInt64Bit

64 ビット符号なし整数テンソル オブジェクト。

TensorUInt8Bit

8 ビット符号なし整数テンソル オブジェクト。

インターフェイス

ILearningModelFeatureDescriptor

すべての機能に含まれる共通プロパティについて説明します。

ILearningModelFeatureValue

フィーチャーのインスタンス化された値。

ILearningModelOperatorProvider

学習モデルのオペラレーターについて説明します。

ITensor

テンソルは多次元値です。

列挙型

LearningModelDeviceKind

機械学習モデルを評価できるデバイスの種類の一覧を定義します。

LearningModelFeatureKind

機械学習モデルの入力機能と出力機能の種類。

LearningModelPixelRange

Windows ML によってサポートされるイメージ名目ピクセル範囲の一覧を定義します。 適切な値は、機械学習モデルのメタデータで指定されます。

TensorKind

サポートされているテンソル データ型の一覧を定義します。

次の例では、モデルの読み込み、評価セッションの作成、モデルの入力および出力機能の取得、それらの特徴のバインド、および評価を行います。

private async Task LoadAndEvaluateModelAsync(VideoFrame _inputFrame, string _modelFileName)
{
    LearningModel _model;
    ImageFeatureDescriptor _inputImageDescription;
    TensorFeatureDescriptor _outputImageDescription;
    LearningModelBinding _binding = null;
    VideoFrame _outputFrame = null;
    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);

        //Get input and output features of the model
        List<ILearningModelFeatureDescriptor> inputFeatures = _model.InputFeatures.ToList();
        List<ILearningModelFeatureDescriptor> outputFeatures = _model.OutputFeatures.ToList();

        // Retrieve the first input feature which is an image
        _inputImageDescription =
                inputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Image)
                as ImageFeatureDescriptor;

        // Retrieve the first output feature which is a tensor
        _outputImageDescription =
                        outputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Tensor)
                        as TensorFeatureDescriptor;

        //Create output frame based on expected image width and height
        _outputFrame = new VideoFrame(
            BitmapPixelFormat.Bgra8, 
            (int)_inputImageDescription.Width, 
            (int)_inputImageDescription.Height);

        //Create binding and then bind input/output features
        _binding = new LearningModelBinding(_session);

        _binding.Bind(_inputImageDescription.Name, _inputFrame);
        _binding.Bind(_outputImageDescription.Name, _outputFrame);

        //Evaluate and get the results
        var results = await _session.EvaluateAsync(_binding, "test");
    }
    catch (Exception ex)
    {
        StatusBlock.Text = $"error: {ex.Message}";
        _model = null;
    }
}

注釈

Windows Server

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

スレッド セーフ

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

こちらもご覧ください