ImageFeatureDescriptor ImageFeatureDescriptor ImageFeatureDescriptor ImageFeatureDescriptor ImageFeatureDescriptor Class

Definition

Describes the properties of the image the model is expecting.

public : sealed class ImageFeatureDescriptor : ILearningModelFeatureDescriptor
struct winrt::Windows::AI::MachineLearning::ImageFeatureDescriptor : ILearningModelFeatureDescriptor
public sealed class ImageFeatureDescriptor : ILearningModelFeatureDescriptor
Public NotInheritable Class ImageFeatureDescriptor Implements ILearningModelFeatureDescriptor
// This class does not provide a public constructor.
Attributes

Windows 10 requirements

Device family
Windows 10, version 1809 (introduced v10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (introduced v1)

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 BitmapAlphaMode BitmapAlphaMode BitmapAlphaMode BitmapAlphaMode

Specifies the expected alpha mode of the image.

BitmapPixelFormat BitmapPixelFormat BitmapPixelFormat BitmapPixelFormat BitmapPixelFormat

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

Description Description Description Description Description

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

Height Height Height Height Height

The expected image height.

IsRequired IsRequired IsRequired IsRequired IsRequired

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

Kind Kind Kind Kind Kind

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

Name Name Name Name Name

The name you use to bind values to this feature.

Width Width Width Width Width

The expected image width.

See also