Windows.AI.MachineLearning Windows.AI.MachineLearning Windows.AI.MachineLearning Windows.AI.MachineLearning Windows.AI.MachineLearning Namespace

Enables apps to load machine learning models, bind features, and evaluate the results.

Classes

ImageFeatureDescriptor ImageFeatureDescriptor ImageFeatureDescriptor ImageFeatureDescriptor ImageFeatureDescriptor

Describes the properties of the image the model is expecting.

ImageFeatureValue ImageFeatureValue ImageFeatureValue ImageFeatureValue ImageFeatureValue

Describes the properties of the image used to pass into a model.

LearningModel LearningModel LearningModel LearningModel LearningModel

Represents a trained machine learning model.

LearningModelBinding LearningModelBinding LearningModelBinding LearningModelBinding LearningModelBinding

Used to bind values to named input and output features.

LearningModelDevice LearningModelDevice LearningModelDevice LearningModelDevice LearningModelDevice

The device used to evaluate the machine learning model.

LearningModelEvaluationResult LearningModelEvaluationResult LearningModelEvaluationResult LearningModelEvaluationResult LearningModelEvaluationResult

Get the results of the evaluation.

LearningModelSession LearningModelSession LearningModelSession LearningModelSession LearningModelSession

Used to evaluate machine learning models.

MapFeatureDescriptor MapFeatureDescriptor MapFeatureDescriptor MapFeatureDescriptor MapFeatureDescriptor

A map is a collection of (key, value) pairs.

SequenceFeatureDescriptor SequenceFeatureDescriptor SequenceFeatureDescriptor SequenceFeatureDescriptor SequenceFeatureDescriptor

A sequence is an array of elements.

TensorBoolean TensorBoolean TensorBoolean TensorBoolean TensorBoolean

A boolean tensor object.

TensorDouble TensorDouble TensorDouble TensorDouble TensorDouble

A 64-bit float tensor object.

TensorFeatureDescriptor TensorFeatureDescriptor TensorFeatureDescriptor TensorFeatureDescriptor TensorFeatureDescriptor

Tensors are multi-dimensional arrays of values.

TensorFloat TensorFloat TensorFloat TensorFloat TensorFloat

A 32-bit float tensor object.

TensorFloat16Bit TensorFloat16Bit TensorFloat16Bit TensorFloat16Bit TensorFloat16Bit

A 16-bit float tensor object.

TensorInt16Bit TensorInt16Bit TensorInt16Bit TensorInt16Bit TensorInt16Bit

A 16-bit signed integer tensor object.

TensorInt32Bit TensorInt32Bit TensorInt32Bit TensorInt32Bit TensorInt32Bit

A 32-bit signed integer tensor object.

TensorInt64Bit TensorInt64Bit TensorInt64Bit TensorInt64Bit TensorInt64Bit

A 64-bit signed integer tensor object.

TensorInt8Bit TensorInt8Bit TensorInt8Bit TensorInt8Bit TensorInt8Bit

An 8-bit signed integer tensor object.

TensorString TensorString TensorString TensorString TensorString

A string tensor object.

TensorUInt16Bit TensorUInt16Bit TensorUInt16Bit TensorUInt16Bit TensorUInt16Bit

A 16-bit unsigned integer tensor object.

TensorUInt32Bit TensorUInt32Bit TensorUInt32Bit TensorUInt32Bit TensorUInt32Bit

A 32-bit unsigned integer tensor object.

TensorUInt64Bit TensorUInt64Bit TensorUInt64Bit TensorUInt64Bit TensorUInt64Bit

A 64-bit unsigned integer tensor object.

TensorUInt8Bit TensorUInt8Bit TensorUInt8Bit TensorUInt8Bit TensorUInt8Bit

A 8-bit unsigned integer tensor object.

Interfaces

ILearningModelFeatureDescriptor ILearningModelFeatureDescriptor ILearningModelFeatureDescriptor ILearningModelFeatureDescriptor ILearningModelFeatureDescriptor

Describes the common properties that all features have.

ILearningModelFeatureValue ILearningModelFeatureValue ILearningModelFeatureValue ILearningModelFeatureValue ILearningModelFeatureValue

The instantiated value for a feature.

ILearningModelOperatorProvider ILearningModelOperatorProvider ILearningModelOperatorProvider ILearningModelOperatorProvider ILearningModelOperatorProvider
ITensor ITensor ITensor ITensor ITensor

Tensors are multi-dimensional values.

Enums

LearningModelDeviceKind LearningModelDeviceKind LearningModelDeviceKind LearningModelDeviceKind LearningModelDeviceKind

Defines the list of device kinds that can evaluate a machine learning model.

LearningModelFeatureKind LearningModelFeatureKind LearningModelFeatureKind LearningModelFeatureKind LearningModelFeatureKind

Input and output feature kinds for a machine learning model.

TensorKind TensorKind TensorKind TensorKind TensorKind

Defines the list of supported tensor data types.

Examples

The following example loads a model, creates an evaluation session, gets the input and output features of the model, binds those features, and evaluates.

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

Remarks

Thread safety

This API is thread-safe.

See also