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

若要在 Windows Server 上使用此 API,您必須搭配桌面體驗使用 Windows Server 2019。

執行緒安全

此 API 是安全線程。

屬性

BitmapAlphaMode

指定影像的預期 Alpha 模式。

BitmapPixelFormat

指定 (通道排序、位深度和資料類型) 的預期像素格式。

Description

在模型中使用此功能的描述。

Height

預期的影像高度。

IsRequired

如果為 true,您必須先將值系結至此功能,才能呼叫 LearningModelSession.Evaluate

Kind

功能類型-使用此類型來知道要使用的衍生類別。

Name

您用來將值系結至此功能的名稱。

PixelRange

提供預期的 LearningModelPixelRange 資訊,以搭配模型使用。

Width

預期的影像寬度。

適用於

另請參閱