ImageFeatureDescriptor Класс

Определение

Описывает свойства изображения, ожидаемого моделью.

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
Наследование
Object Platform::Object IInspectable ImageFeatureDescriptor
Атрибуты
Реализации

Требования к Windows

Семейство устройств
Windows 10, version 1809 (появилось в 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (появилось в v1.0)

Примеры

В следующем примере выполняется загрузка модели из локального файла, создание сеанса и получение входных и выходных функций.

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

Комментарии

Windows Server

Чтобы использовать этот API в Windows Server, необходимо использовать Windows Server 2019 с возможностями рабочего стола.

Потокобезопасность

Этот API является потокобезопасным.

Свойства

BitmapAlphaMode

Указывает ожидаемый альфа-режим изображения.

BitmapPixelFormat

Указывает ожидаемый формат пикселей (упорядочение каналов, битовая глубина и тип данных).

Description

Описание того, для чего используется эта функция в модели.

Height

Ожидаемая высота изображения.

IsRequired

Если значение равно true, необходимо привязать значение к этой функции перед вызовом LearningModelSession.Evaluate.

Kind

Тип функции — используйте его, чтобы узнать, какой производный класс использовать.

Name

Имя, используемое для привязки значений к этой функции.

PixelRange

Предоставляет ожидаемые сведения LearningModelPixelRange для использования с моделью.

Width

Ожидаемая ширина изображения.

Применяется к

См. также раздел