LearningModelBinding.Bind 메서드

정의

오버로드

Bind(String, Object)

명명된 기능에 값을 바인딩합니다.

Bind(String, Object, IPropertySet)

속성을 사용하여 명명된 기능에 값을 바인딩하여 바인딩을 제어합니다.

Bind(String, Object)

명명된 기능에 값을 바인딩합니다.

public:
 virtual void Bind(Platform::String ^ name, Platform::Object ^ value) = Bind;
/// [Windows.Foundation.Metadata.Overload("Bind")]
void Bind(winrt::hstring const& name, IInspectable const& value);
[Windows.Foundation.Metadata.Overload("Bind")]
public void Bind(string name, object value);
function bind(name, value)
Public Sub Bind (name As String, value As Object)

매개 변수

name
String

Platform::String

winrt::hstring

기능의 이름입니다.

value
Object

Platform::Object

IInspectable

바인딩할 값입니다.

특성

예제

다음 예제에서는 첫 번째 입력 및 출력 기능을 검색하고, 출력 프레임을 만들고, 입력 및 출력 기능을 바인딩하고, 회피합니다.

private async Task EvaluateModelAsync(
    VideoFrame _inputFrame, 
    LearningModelSession _session, 
    IReadOnlyList<ILearningModelFeatureDescriptor> _inputFeatures, 
    IReadOnlyList<ILearningModelFeatureDescriptor> _outputFeatures,
    LearningModel _model)
{
    ImageFeatureDescriptor _inputImageDescription;
    TensorFeatureDescriptor _outputImageDescription;
    LearningModelBinding _binding = null;
    VideoFrame _outputFrame = null;

    try
    {
        // 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는 스레드로부터 안전합니다.

적용 대상

Bind(String, Object, IPropertySet)

속성을 사용하여 명명된 기능에 값을 바인딩하여 바인딩을 제어합니다.

public:
 virtual void Bind(Platform::String ^ name, Platform::Object ^ value, IPropertySet ^ props) = Bind;
/// [Windows.Foundation.Metadata.Overload("BindWithProperties")]
void Bind(winrt::hstring const& name, IInspectable const& value, IPropertySet const& props);
[Windows.Foundation.Metadata.Overload("BindWithProperties")]
public void Bind(string name, object value, IPropertySet props);
function bind(name, value, props)
Public Sub Bind (name As String, value As Object, props As IPropertySet)

매개 변수

name
String

Platform::String

winrt::hstring

바인딩할 기능의 이름입니다.

value
Object

Platform::Object

IInspectable

기능에 바인딩할 값입니다.

props
IPropertySet

바인딩의 텐서화 및 디텐서화 동작을 설명하는 키-값 쌍이 있는 속성 맵입니다. 자세한 내용은 설명 섹션을 참조 하세요 .

특성

설명

다음은 props 매개 변수에 대한 유효한 키-값 쌍입니다.

이름 Description
BitmapBounds PropertyType.UInt32Array 입력을 바인딩할 때 BitmapBounds 속성은 자르기 경계를 지정합니다. 잘린 이미지는 추출되어 유추를 수행하기 위한 입력으로 사용됩니다.

출력을 바인딩할 때 BitmapBounds 속성은 대상 출력 영역의 경계를 지정합니다. 유추 결과는 바인딩된 이미지 내의 대상 출력 영역에 기록됩니다.

BitmapBounds 속성은 값 [left, top, width, height]이 인 UInt32 배열로 지정됩니다.

이 속성은 ImageFeatureValue를 바인딩할 때만 적용됩니다.
BitmapPixelFormat PropertyType.Int32 입력 또는 출력을 바인딩할 때 BitmapPixelFormat 속성은 모델 작성자가 특정 기능 값에 대해 의도한 픽셀 형식을 지정합니다. ONNX 모델의 Image 메타데이터에서 Image.BitmapPixelFormat 메타데이터가 누락된 경우 이 속성을 사용하여 런타임에 지정할 수 있습니다. 바인딩된 이미지는 모델에서 사용할 수 있도록 지정된 픽셀 형식으로 자동으로 변환됩니다.

BitmapPixelFormat은 Windows.Graphics.Imaging.BitmapPixelFormat 열거형의 값에 해당하는 Int32 값으로 지정되어야 합니다. 현재 지원되는 값은 다음과 같습니다.
  • BitmapPixelFormat.Rgba8
  • BitmapPixelFormat.Bgra8
  • BitmapPixelFormat.Gray8
이 속성은 ImageFeatureValue를 바인딩할 때만 적용됩니다.
DisableTensorCpuSync PropertyType.Boolean ID3D12Resource에서 백업하는 출력 텐서를 바인딩할 때 DisableTensorCpuSync 속성을 사용하여 GPU/NPU 출력을 CPU 텐서로 다시 복사하지 못하도록 할 수 있습니다. 기본적으로 LearningModelSession.Evaluate API 호출은 차단 호출이며 완료 후 CPU에서 유추 결과를 사용할 수 있도록 합니다.

특정 GPU/NPU 평가 시나리오에서는 GPU/NPU에 대한 유추 결과를 유지하는 것이 좋습니다. 그리고 결과를 CPU에 다시 복사하는 것은 불필요하고 느립니다. 해당 복사를 방지하려면 바인딩하는 동안 DisableTensorCpuSync 속성을 사용하도록 설정합니다.

이 속성은 ITensor 또는 구체적인 형식(즉, TensorFloat)을 바인딩할 때만 적용됩니다.

이 속성은 Windows 11 버전 21H2(10.0; 빌드 22000).
PixelRange PropertyType.Int32 입력 또는 출력을 바인딩할 때 PixelRange 속성은 모델 작성자가 특정 기능 값에 대해 의도한 정규화 범위를 지정합니다. ONNX 모델의 Image 메타데이터에서 Image.NominalPixelRange 메타데이터가 누락된 경우 이 속성을 사용하여 런타임에 지정할 수 있습니다. 바인딩된 이미지는 모델에서 사용할 수 있도록 지정된 정규화된 범위로 자동으로 변환됩니다.

PixelRange는 Windows.AI.MachineLearning.LearningModelPixelRange 열거형의 값에 해당하는 Int32 값으로 지정해야 합니다.

이 속성은 ImageFeatureValue를 바인딩할 때만 적용됩니다.

Windows Server

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

스레드로부터의 안전성

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

적용 대상