Windows.AI.MachineLearning Spazio dei nomi

Consente alle app di caricare i modelli di Machine Learning, associare le funzionalità e valutare i risultati.

Classi

ImageFeatureDescriptor

Descrive le proprietà dell'immagine prevista dal modello.

ImageFeatureValue

Descrive le proprietà dell'immagine usata per passare a un modello.

LearningModel

Rappresenta un modello di Machine Learning sottoposto a training.

LearningModelBinding

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

LearningModelDevice

Dispositivo usato per valutare il modello di Machine Learning.

LearningModelEvaluationResult

Ottenere i risultati della valutazione.

LearningModelSession

Usato per valutare i modelli di Machine Learning.

LearningModelSessionOptions

Descrive le opzioni di inferenza usate durante la creazione di oggetti LearningModelSession .

MapFeatureDescriptor

Una mappa è una raccolta di coppie chiave, valore.

SequenceFeatureDescriptor

Una sequenza è una matrice di elementi.

TensorBoolean

Oggetto tensor booleano.

TensorDouble

Oggetto tensore float a 64 bit.

TensorFeatureDescriptor

I tensori sono matrici multidimensionali di valori.

TensorFloat

Oggetto tensore float a 32 bit.

TensorFloat16Bit

Oggetto tensore float a 16 bit.

TensorInt16Bit

Oggetto tensore intero con segno a 16 bit.

TensorInt32Bit

Oggetto tensore intero con segno a 32 bit.

TensorInt64Bit

Oggetto tensore intero con segno a 64 bit.

TensorInt8Bit

Oggetto tensore intero con segno a 8 bit.

TensorString

Oggetto tensore stringa.

TensorUInt16Bit

Oggetto tensore intero senza segno a 16 bit.

TensorUInt32Bit

Oggetto tensore intero senza segno a 32 bit.

TensorUInt64Bit

Oggetto tensore intero senza segno a 64 bit.

TensorUInt8Bit

Oggetto tensore intero senza segno a 8 bit.

Interfacce

ILearningModelFeatureDescriptor

Descrive le proprietà comuni che tutte le funzionalità hanno.

ILearningModelFeatureValue

Valore creato per una funzionalità.

ILearningModelOperatorProvider

Descrive gli operatori per un modello di apprendimento.

ITensor

I tensori sono valori multidimensionali.

Enumerazioni

LearningModelDeviceKind

Definisce l'elenco di tipi di dispositivo che possono valutare un modello di Machine Learning.

LearningModelFeatureKind

Tipi di funzionalità di input e output per un modello di Machine Learning.

LearningModelPixelRange

Definisce l'elenco dell'intervallo di pixel nominale dell'immagine supporto da Windows ML. Il valore appropriato viene specificato nei metadati di un modello di Machine Learning.

TensorKind

Definisce l'elenco dei tipi di dati tensor supportati.

Esempio

L'esempio seguente carica un modello, crea una sessione di valutazione, ottiene le funzionalità di input e output del modello, associa tali funzionalità e valuta.

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

Commenti

Windows Server

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

Thread safety

Questa API è thread-safe.

Vedi anche