Share via


LearningModelBinding Klasse

Definition

Wird verwendet, um Werte an benannte Eingabe- und Ausgabefeatures zu binden.

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)
Vererbung
Object Platform::Object IInspectable LearningModelBinding
Attribute
Implementiert
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-Anforderungen

Gerätefamilie
Windows 10, version 1809 (eingeführt in 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (eingeführt in v1.0)

Beispiele

Im folgenden Beispiel werden die ersten Eingabe- und Ausgabefeatures abgerufen, ein Ausgabeframe erstellt, die Eingabe- und Ausgabefeatures gebunden und evakuiert.

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;
    }
}

Hinweise

Modelle geben ihre Eingabe- und Ausgabefeatures mithilfe eindeutiger Zeichenfolgennamen an. Vor dem Auswerten des Modells können Sie Ihre Eingaben und Ausgaben mithilfe dieser Namen an die Sitzung binden. Verwenden Sie dazu das LearningModelBinding-Objekt , das Sie basierend auf einer Sitzung erstellen können.

Windows Server

Um diese API unter Windows Server verwenden zu können, müssen Sie Windows Server 2019 mit Desktopdarstellung verwenden.

Threadsicherheit

Diese API ist threadsicher.

Konstruktoren

LearningModelBinding(LearningModelSession)

Erstellt eine LearningModelBinding aus der angegebenen LearningModelSession.

Eigenschaften

Size

Ruft die Anzahl der Elemente in der Zuordnung ab.

Methoden

Bind(String, Object)

Binden Sie einen Wert an das benannte Feature.

Bind(String, Object, IPropertySet)

Binden Sie einen Wert an das benannte Feature mithilfe von Eigenschaften, um die Bindung zu steuern.

Clear()

Entfernen Sie alle Bindungen.

First()

Gibt einen Iterator zurück, der mit dem ersten Element der Zuordnungsansicht initialisiert wird.

HasKey(String)

Bestimmt, ob die Kartenansicht den angegebenen Schlüssel enthält.

Lookup(String)

Gibt das Element am angegebenen Schlüssel in der Kartenansicht zurück.

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

Teilt die Kartenansicht in zwei Ansichten auf.

Gilt für:

Weitere Informationen