LearningModelBinding クラス

定義

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

public ref class LearningModelBinding sealed : IIterable<IKeyValuePair<Platform::String ^, Platform::Object ^> ^>, IMapView<Platform::String ^, Platform::Object ^>
/// [Windows.Foundation.Metadata.Activatable(Windows.AI.MachineLearning.ILearningModelBindingFactory, 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 LearningModelBinding final : IIterable<IKeyValuePair<winrt::hstring, IInspectable const&>>, IMapView<winrt::hstring, IInspectable const&>
[Windows.Foundation.Metadata.Activatable(typeof(Windows.AI.MachineLearning.ILearningModelBindingFactory), 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 LearningModelBinding : IEnumerable<KeyValuePair<string,object>>, IReadOnlyDictionary<string,object>
function LearningModelBinding(session)
Public NotInheritable Class LearningModelBinding
Implements IEnumerable(Of KeyValuePair(Of String, Object)), IReadOnlyDictionary(Of String, Object)
継承
Object Platform::Object IInspectable LearningModelBinding
属性
実装
IIterable<IKeyValuePair<K,V>> IEnumerable<KeyValuePair<K,V>> IIterable<IKeyValuePair<String,Object>> IEnumerable<KeyValuePair<String,Object>> IIterable<IKeyValuePair<Platform::String,Platform::Object>> IIterable<IKeyValuePair<winrt::hstring,IInspectable>> IMapView<String,Object> IReadOnlyDictionary<String,Object> IMapView<Platform::String,Platform::Object> IMapView<winrt::hstring,IInspectable>

Windows の要件

デバイス ファミリ
Windows 10, version 1809 (10.0.17763.0 で導入)
API contract
Windows.AI.MachineLearning.MachineLearningContract (v1.0 で導入)

次の例では、最初の入力と出力の特徴を取得し、出力フレームを作成し、入力と出力の特徴をバインドして、回避します。

private async Task EvaluateModelAsync(
    VideoFrame _inputFrame, 
    LearningModelSession _session, 
    IReadOnlyList<ILearningModelFeatureDescriptor> _inputFeatures, 
    IReadOnlyList<ILearningModelFeatureDescriptor> _outputFeatures,
    LearningModel _model)
{
    ImageFeatureDescriptor _inputImageDescription;
    TensorFeatureDescriptor _outputImageDescription;
    LearningModelBinding _binding = null;
    VideoFrame _outputFrame = null;

    try
    {
        // 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;
    }
}

注釈

モデルでは、一意の文字列名を使用して入力機能と出力機能を指定します。 モデルを評価する前に、これらの名前を使用して入力と出力をセッションにバインドできます。 これを行うには、セッションに基づいて作成できる LearningModelBinding オブジェクトを使用します。

Windows Server

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

スレッド セーフ

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

コンストラクター

LearningModelBinding(LearningModelSession)

指定した LearningModelSession から LearningModelBinding を作成します。

プロパティ

Size

マップ内の要素の数を取得します。

メソッド

Bind(String, Object)

名前付き機能に値をバインドします。

Bind(String, Object, IPropertySet)

プロパティを使用して名前付き機能に値をバインドし、バインドを制御します。

Clear()

すべてのバインドを削除します。

First()

マップ ビュー内の最初の要素に初期化される反復子を返します。

HasKey(String)

マップ ビューに指定したキーが含まれているかどうかを判断します。

Lookup(String)

マップ ビューの指定したキーにある項目を返します。

Split(IMapView<String,Object>, IMapView<String,Object>)

マップ ビューを 2 つのビューに分割します。

適用対象

こちらもご覧ください