共用方式為


LearningModel.InputFeatures 屬性

定義

模型的輸入特徵清單。

public:
 property IVectorView<ILearningModelFeatureDescriptor ^> ^ InputFeatures { IVectorView<ILearningModelFeatureDescriptor ^> ^ get(); };
IVectorView<ILearningModelFeatureDescriptor> InputFeatures();
public IReadOnlyList<ILearningModelFeatureDescriptor> InputFeatures { get; }
var iVectorView = learningModel.inputFeatures;
Public ReadOnly Property InputFeatures As IReadOnlyList(Of ILearningModelFeatureDescriptor)

屬性值

模型的輸入特徵清單。

範例

下列範例會從本機檔案載入模型、從模型建立會話,以及取得模型的輸入和輸出功能。

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 是安全線程。

適用於