Windows.AI.MachineLearning 네임스페이스

앱에서 기계 학습 모델을 로드하고, 기능을 바인딩하고, 결과를 평가할 수 있습니다.

클래스

ImageFeatureDescriptor

모델이 예상하는 이미지의 속성을 설명합니다.

ImageFeatureValue

모델에 전달하는 데 사용되는 이미지의 속성을 설명합니다.

LearningModel

학습된 기계 학습 모델을 나타냅니다.

LearningModelBinding

명명된 입력 및 출력 기능에 값을 바인딩하는 데 사용됩니다.

LearningModelDevice

기계 학습 모델을 평가하는 데 사용되는 디바이스입니다.

LearningModelEvaluationResult

평가 결과를 가져옵니다.

LearningModelSession

기계 학습 모델을 평가하는 데 사용됩니다.

LearningModelSessionOptions

LearningModelSession 개체를 만드는 동안 사용되는 유추 옵션에 대해 설명합니다.

MapFeatureDescriptor

맵은 (키, 값) 쌍의 컬렉션입니다.

SequenceFeatureDescriptor

시퀀스는 요소의 배열입니다.

TensorBoolean

부울 텐서 개체입니다.

TensorDouble

64비트 float 텐서 개체입니다.

TensorFeatureDescriptor

텐서 값의 다차원 배열입니다.

TensorFloat

32비트 float 텐서 개체입니다.

TensorFloat16Bit

16비트 float 텐서 개체입니다.

TensorInt16Bit

16비트 부속 정수 텐서 개체입니다.

TensorInt32Bit

32비트 부속 정수 텐서 개체입니다.

TensorInt64Bit

64비트 부속 정수 텐서 개체입니다.

TensorInt8Bit

8비트 부속 정수 텐서 개체입니다.

TensorString

문자열 텐서 개체입니다.

TensorUInt16Bit

부호 없는 16비트 정수 텐서 개체입니다.

TensorUInt32Bit

부호 없는 32비트 정수 텐서 개체입니다.

TensorUInt64Bit

부호 없는 64비트 정수 텐서 개체입니다.

TensorUInt8Bit

부호 없는 8비트 정수 텐서 개체입니다.

인터페이스

ILearningModelFeatureDescriptor

모든 기능에 있는 일반적인 속성에 대해 설명합니다.

ILearningModelFeatureValue

기능에 대한 인스턴스화된 값입니다.

ILearningModelOperatorProvider

학습 모델의 오페라를 설명합니다.

ITensor

텐서가 다차원 값입니다.

열거형

LearningModelDeviceKind

기계 학습 모델을 평가할 수 있는 디바이스 종류의 목록을 정의합니다.

LearningModelFeatureKind

기계 학습 모델에 대한 입력 및 출력 기능 종류입니다.

LearningModelPixelRange

Windows ML에서 제공하는 이미지 명목 픽셀 범위 목록을 정의합니다. 적절한 값은 기계 학습 모델의 메타데이터에 지정됩니다.

TensorKind

지원되는 텐서 데이터 형식 목록을 정의합니다.

예제

다음 예제에서는 모델을 로드하고, 평가 세션을 만들고, 모델의 입력 및 출력 기능을 가져오고, 해당 기능을 바인딩하고, 평가합니다.

private async Task LoadAndEvaluateModelAsync(VideoFrame _inputFrame, string _modelFileName)
{
    LearningModel _model;
    ImageFeatureDescriptor _inputImageDescription;
    TensorFeatureDescriptor _outputImageDescription;
    LearningModelBinding _binding = null;
    VideoFrame _outputFrame = null;
    LearningModelSession _session;

    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;

        //Create output frame based on expected image width and height
        _outputFrame = new VideoFrame(
            BitmapPixelFormat.Bgra8, 
            (int)_inputImageDescription.Width, 
            (int)_inputImageDescription.Height);

        //Create binding and then bind input/output features
        _binding = new LearningModelBinding(_session);

        _binding.Bind(_inputImageDescription.Name, _inputFrame);
        _binding.Bind(_outputImageDescription.Name, _outputFrame);

        //Evaluate and get the results
        var results = await _session.EvaluateAsync(_binding, "test");
    }
    catch (Exception ex)
    {
        StatusBlock.Text = $"error: {ex.Message}";
        _model = null;
    }
}

설명

Windows Server

Windows Server에서 이 API를 사용하려면 데스크톱 환경에서 Windows Server 2019를 사용해야 합니다.

스레드로부터의 안전성

이 API는 스레드로부터 안전합니다.

추가 정보