Condividi tramite


LearningModelBinding Classe

Definizione

Usato per associare valori alle funzionalità di input e output denominate.

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)
Ereditarietà
Object Platform::Object IInspectable LearningModelBinding
Attributi
Implementazioni
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>

Requisiti Windows

Famiglia di dispositivi
Windows 10, version 1809 (è stato introdotto in 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (è stato introdotto in v1.0)

Esempio

Nell'esempio seguente vengono recuperate le prime funzionalità di input e output, viene creato un frame di output, vengono associate le funzionalità di input e output ed evase.

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

Commenti

I modelli specificano le relative funzionalità di input e output usando nomi di stringa univoci. Prima di valutare il modello, è possibile associare gli input e gli output alla sessione usando tali nomi. A tale scopo, utilizzare l'oggetto LearningModelBinding che è possibile creare in base a una sessione.

Windows Server

Per usare questa API in Windows Server, è necessario usare Windows Server 2019 con Esperienza desktop.

Thread safety

Questa API è thread-safe.

Costruttori

LearningModelBinding(LearningModelSession)

Crea un oggetto LearningModelBinding dall'oggetto LearningModelSession specificato.

Proprietà

Size

Ottiene il numero di elementi nella mappa.

Metodi

Bind(String, Object)

Associare un valore alla funzionalità denominata.

Bind(String, Object, IPropertySet)

Associare un valore alla funzionalità denominata usando le proprietà per controllare l'associazione.

Clear()

Rimuovere tutte le associazioni.

First()

Restituisce un iteratore che viene inizializzato al primo elemento nella visualizzazione della mappa.

HasKey(String)

Determina se la visualizzazione mappa contiene la chiave specificata.

Lookup(String)

Restituisce l'elemento in corrispondenza della chiave specificata nella visualizzazione mappa.

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

Suddivide la visualizzazione mappa in due visualizzazioni.

Si applica a

Vedi anche