LearningModelSessionOptions.OverrideNamedDimension(String, UInt32) Method

Definition

Provides the ability to override named input dimensions of a Learning Model to concrete values.

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)

Parameters

name
String

Platform::String

winrt::hstring

The name of the input dimension to set.

dimension
UInt32

unsigned int

uint32_t

The concrete value to assign to the specified dimension.

Windows requirements

Device family
Windows 10, version 2104 (introduced in 10.0.20348.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (introduced in v4.0)

Examples

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);
}

Remarks

Using this API can yield performance improvements, as it allows for preallocation of tensors during session creation that would otherwise be allocated during model evaluation.

Applies to