LearningModelDevice LearningModelDevice LearningModelDevice LearningModelDevice LearningModelDevice Class


The device used to evaluate the machine learning model.

public : sealed class LearningModelDevice
struct winrt::Windows::AI::MachineLearning::LearningModelDevice
public sealed class LearningModelDevice
Public NotInheritable Class LearningModelDevice
var learningModelDevice = new learningModelDevice(deviceKind);

Windows 10 requirements

Device family
Windows 10, version 1809 (introduced v10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (introduced v1)


The following example loads a model, selects the device on which to evaluate the model, and creates an evaluation session.

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

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

To use this API on Windows Server, you must use Windows Server 2019 with Desktop Experience.

Thread safety

This API is thread-safe.


LearningModelDevice(LearningModelDeviceKind) LearningModelDevice(LearningModelDeviceKind) LearningModelDevice(LearningModelDeviceKind) LearningModelDevice(LearningModelDeviceKind) LearningModelDevice(LearningModelDeviceKind)

Create a LearningModelDevice from the specified LearningModelDeviceKind.


AdapterId AdapterId AdapterId AdapterId AdapterId

Returns the unique identifier for the device.

Direct3D11Device Direct3D11Device Direct3D11Device Direct3D11Device Direct3D11Device

Returns the IDirect3DDevice for the device.


CreateFromDirect3D11Device(IDirect3DDevice) CreateFromDirect3D11Device(IDirect3DDevice) CreateFromDirect3D11Device(IDirect3DDevice) CreateFromDirect3D11Device(IDirect3DDevice) CreateFromDirect3D11Device(IDirect3DDevice)

Create a LearningModelDevice from the specified IDirect3DDevice.

See also