Share via


ImageFeatureDescriptor Class

Definition

Describes the properties of the image the model is expecting.

public ref class ImageFeatureDescriptor sealed : ILearningModelFeatureDescriptor
/// [Windows.Foundation.Metadata.ContractVersion(Windows.AI.MachineLearning.MachineLearningContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ImageFeatureDescriptor final : ILearningModelFeatureDescriptor
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.AI.MachineLearning.MachineLearningContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ImageFeatureDescriptor : ILearningModelFeatureDescriptor
Public NotInheritable Class ImageFeatureDescriptor
Implements ILearningModelFeatureDescriptor
Inheritance
Object Platform::Object IInspectable ImageFeatureDescriptor
Attributes
Implements

Windows requirements

Device family
Windows 10, version 1809 (introduced in 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (introduced in v1.0)

Examples

The following example loads a model from a local file, creates a session from it, and gets the input and output features.

private async Task LoadModelAsync(string _modelFileName)
{
    LearningModel _model;
    LearningModelSession _session;
    ImageFeatureDescriptor _inputImageDescription;
    TensorFeatureDescriptor _outputImageDescription;

    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;
    }
    catch (Exception ex)
    {
        StatusBlock.Text = $"error: {ex.Message}";
        _model = null;
    }
}

Remarks

Windows Server

To use this API on Windows Server, you must use Windows Server 2019 with Desktop Experience.

Thread safety

This API is thread-safe.

Properties

BitmapAlphaMode

Specifies the expected alpha mode of the image.

BitmapPixelFormat

Specifies the expected pixel format (channel ordering, bit depth, and data type).

Description

A description of what this feature is used for in the model.

Height

The expected image height.

IsRequired

If true, you must bind a value to this feature before calling LearningModelSession.Evaluate.

Kind

The kind of feature—use this to know which derived class to use.

Name

The name you use to bind values to this feature.

PixelRange

Provides the expected LearningModelPixelRange information for use with the model.

Width

The expected image width.

Applies to

See also