LearningModelSession Constructores

Definición

Sobrecargas

LearningModelSession(LearningModel)

Crea una sesión mediante el dispositivo predeterminado.

LearningModelSession(LearningModel, LearningModelDevice)

Crea una sesión mediante el dispositivo especificado.

LearningModelSession(LearningModel, LearningModelDevice, LearningModelSessionOptions)

Crea una sesión con el dispositivo especificado y las opciones de inferencia adicionales.

LearningModelSession(LearningModel)

Crea una sesión mediante el dispositivo predeterminado.

public:
 LearningModelSession(LearningModel ^ model);
 LearningModelSession(LearningModel const& model);
public LearningModelSession(LearningModel model);
function LearningModelSession(model)
Public Sub New (model As LearningModel)

Parámetros

model
LearningModel

Modelo de aprendizaje automático entrenado para esta sesión.

Ejemplos

En el ejemplo siguiente se carga un modelo y se crea una sesión de evaluación con él.

private async Task LoadModelAsync(LearningModel _model, string _modelFileName, LearningModelSession _session)
{
    // Only load the model one time.
    if (_model != null) return;

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

        // Create the evaluation session with the model and device.
        _session = new LearningModelSession(_model);
    }
    catch (Exception ex)
    {
        StatusBlock.Text = $"error: {ex.Message}";
        _model = null;
    }
}

Comentarios

Windows Server

Para usar esta API en Windows Server, debe usar Windows Server 2019 con experiencia de escritorio.

Seguridad para subprocesos

Esta API es segura para subprocesos.

Se aplica a

LearningModelSession(LearningModel, LearningModelDevice)

Crea una sesión mediante el dispositivo especificado.

public:
 LearningModelSession(LearningModel ^ model, LearningModelDevice ^ deviceToRunOn);
 LearningModelSession(LearningModel const& model, LearningModelDevice const& deviceToRunOn);
public LearningModelSession(LearningModel model, LearningModelDevice deviceToRunOn);
function LearningModelSession(model, deviceToRunOn)
Public Sub New (model As LearningModel, deviceToRunOn As LearningModelDevice)

Parámetros

model
LearningModel

Modelo de aprendizaje automático entrenado para esta sesión.

deviceToRunOn
LearningModelDevice

Dispositivo de evaluación de la sesión.

Ejemplos

En el ejemplo siguiente se carga un modelo, se selecciona el dispositivo en el que se va a evaluar el modelo y se crea una sesión de evaluación.

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

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

Comentarios

Windows Server

Para usar esta API en Windows Server, debe usar Windows Server 2019 con experiencia de escritorio.

Seguridad para subprocesos

Esta API es segura para subprocesos.

Se aplica a

LearningModelSession(LearningModel, LearningModelDevice, LearningModelSessionOptions)

Crea una sesión con el dispositivo especificado y las opciones de inferencia adicionales.

public:
 LearningModelSession(LearningModel ^ model, LearningModelDevice ^ deviceToRunOn, LearningModelSessionOptions ^ learningModelSessionOptions);
 LearningModelSession(LearningModel const& model, LearningModelDevice const& deviceToRunOn, LearningModelSessionOptions const& learningModelSessionOptions);
public LearningModelSession(LearningModel model, LearningModelDevice deviceToRunOn, LearningModelSessionOptions learningModelSessionOptions);
function LearningModelSession(model, deviceToRunOn, learningModelSessionOptions)
Public Sub New (model As LearningModel, deviceToRunOn As LearningModelDevice, learningModelSessionOptions As LearningModelSessionOptions)

Parámetros

model
LearningModel

Modelo de aprendizaje automático entrenado para esta sesión.

deviceToRunOn
LearningModelDevice

Dispositivo de evaluación de la sesión.

learningModelSessionOptions
LearningModelSessionOptions

Las opciones usadas para configurar la creación y evaluación de la sesión.

Requisitos de Windows

Familia de dispositivos
Windows 10, version 1903 (se introdujo en la versión 10.0.18362.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (se introdujo en la versión v2.0)

Ejemplos

En el ejemplo siguiente se carga un modelo y se configura una sesión de evaluación mediante LearningModelSessionOptions.

private LearningModelSessionOptions CreateSessionOptions()
{
    var options = new LearningModelSessionOptions();

    // Disable constant batch size optimizations
    options.BatchSizeOverride = 0;

    return options;
}

private async Task LoadModelAsync(string modelFileName)
{
    LearningModel model;
    LearningModelDevice device;
    LearningModelSession session;

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

        // Create default LearningModelDevice.
        device = new LearningModelDevice(LearningModelDeviceKind.Default);

        // Create LearningModelSessionOptions with necessary options set.
        LearningModelSessionOptions options = CreateSessionOptions();

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

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

Se aplica a