LearningModelDevice 类

定义

用于评估机器学习模型的设备。

public ref class LearningModelDevice sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.AI.MachineLearning.ILearningModelDeviceFactory, 65536, "Windows.AI.MachineLearning.MachineLearningContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.AI.MachineLearning.MachineLearningContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class LearningModelDevice final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.AI.MachineLearning.ILearningModelDeviceFactory), 65536, "Windows.AI.MachineLearning.MachineLearningContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.AI.MachineLearning.MachineLearningContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class LearningModelDevice
function LearningModelDevice(deviceKind)
Public NotInheritable Class LearningModelDevice
继承
Object Platform::Object IInspectable LearningModelDevice
属性

Windows 要求

设备系列
Windows 10, version 1809 (在 10.0.17763.0 中引入)
API contract
Windows.AI.MachineLearning.MachineLearningContract (在 v1.0 中引入)

示例

以下示例加载模型,选择要评估模型的设备,并创建评估会话。

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 是线程安全的。

构造函数

LearningModelDevice(LearningModelDeviceKind)

从指定的 LearningModelDeviceKind 创建 LearningModelDevice

属性

AdapterId

返回设备的唯一标识符。

Direct3D11Device

返回设备的 IDirect3DDevice

方法

CreateFromDirect3D11Device(IDirect3DDevice)

从指定的 IDirect3DDevice 创建 LearningModelDevice

适用于

另请参阅