Share via


LearningModelDevice Classe

Definição

O dispositivo usado para avaliar o modelo de machine learning.

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
Herança
Object Platform::Object IInspectable LearningModelDevice
Atributos

Requisitos do Windows

Família de dispositivos
Windows 10, version 1809 (introduzida na 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (introduzida na v1.0)

Exemplos

O exemplo a seguir carrega um modelo, seleciona o dispositivo no qual avaliar o modelo e cria uma sessão de avaliação.

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

Comentários

Windows Server

Para usar essa API no Windows Server, você deve usar o Windows Server 2019 com a Experiência desktop.

Acesso thread-safe

Essa API é thread-safe.

Construtores

LearningModelDevice(LearningModelDeviceKind)

Crie um LearningModelDevice do LearningModelDeviceKind especificado.

Propriedades

AdapterId

Retorna o identificador exclusivo para o dispositivo.

Direct3D11Device

Retorna o IDirect3DDevice para o dispositivo.

Métodos

CreateFromDirect3D11Device(IDirect3DDevice)

Crie um LearningModelDevice do IDirect3DDevice especificado.

Aplica-se a

Confira também