LearningModelDeviceKind 列舉

定義

定義可評估機器學習模型的裝置種類清單。

public enum class LearningModelDeviceKind
/// [Windows.Foundation.Metadata.ContractVersion(Windows.AI.MachineLearning.MachineLearningContract, 65536)]
enum class LearningModelDeviceKind
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.AI.MachineLearning.MachineLearningContract), 65536)]
public enum LearningModelDeviceKind
var value = Windows.AI.MachineLearning.LearningModelDeviceKind.default
Public Enum LearningModelDeviceKind
繼承
LearningModelDeviceKind
屬性

Windows 需求

裝置系列
Windows 10, version 1809 (已於 10.0.17763.0 引進)
API contract
Windows.AI.MachineLearning.MachineLearningContract (已於 v1.0 引進)

欄位

Cpu 1

使用 CPU 來評估模型。

Default 0

讓系統決定要使用的裝置。

DirectX 2

使用 GPU 或其他 DirectX 裝置來評估模型。

DirectXHighPerformance 3

使用系統原則定義的裝置來達到高效能。

DirectXMinPower 4

使用系統原則定義的裝置來取得最小電源。

範例

下列範例會載入模型、選取要評估模型的裝置,並建立評估會話。

private async Task LoadModelAsync(string _modelFileName, bool _useGPU)
{
    LearningModel _model;
    LearningModelSession _session;

    try
    {
        // Load and create the model
        var modelFile = 
            await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/{_modelFileName}"));
        _model = await LearningModel.LoadFromStorageFileAsync(modelFile);

        // Select the device to evaluate on
        LearningModelDevice device = null;
        if (_useGPU)
        {
            // Use a GPU or other DirectX device to evaluate the model.
            device = new LearningModelDevice(LearningModelDeviceKind.DirectX);
        }
        else
        {
            // Use the CPU to evaluate the model.
            device = new LearningModelDevice(LearningModelDeviceKind.Cpu);
        }

        // Create the evaluation session with the model and device.
        _session = new LearningModelSession(_model, device);

    }
    catch (Exception ex)
    {
        StatusBlock.Text = $"error: {ex.Message}";
        _model = null;
    }
}

備註

如果未指定,系統會決定要使用的裝置。

Windows Server

若要在 Windows Server 上使用此 API,您必須搭配桌面體驗使用 Windows Server 2019。

執行緒安全

此 API 是安全線程。

適用於

另請參閱