共用方式為


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 可以產生效能改善,因為它允許在建立會話期間預先配置張量,否則會在模型評估期間配置。

適用於