LearningModelSessionOptions.OverrideNamedDimension(String, UInt32) 方法

定义

提供将学习模型的命名输入维度重写为具体值的功能。

public:
 virtual void OverrideNamedDimension(Platform::String ^ name, unsigned int dimension) = OverrideNamedDimension;
void OverrideNamedDimension(winrt::hstring const& name, uint32_t const& dimension);
public void OverrideNamedDimension(string name, uint dimension);
function overrideNamedDimension(name, dimension)
Public Sub OverrideNamedDimension (name As String, dimension As UInteger)

参数

name
String

Platform::String

winrt::hstring

要设置的输入维度的名称。

dimension
UInt32

unsigned int

uint32_t

要分配给指定维度的具体值。

Windows 要求

设备系列
Windows 10, version 2104 (在 10.0.20348.0 中引入)
API contract
Windows.AI.MachineLearning.MachineLearningContract (在 v4.0 中引入)

示例

void SetNamedDimensionOverrides(LearningModel model) {
    // Create LearningModelSessionOptions
    auto options = LearningModelSessionOptions();

    // Override a named input dimension to a concrete value
    options->OverrideNamedDimension(L"dimension_name", 256);

    // Create session
    LearningModelSession session = nullptr;
    session = LearningModelSession(model, LearningModelDeviceKind::GPU, options);
}

注解

使用此 API 可提高性能,因为它允许在会话创建期间预先分配张量,否则会在模型评估期间分配这些张量。

适用于