Freigeben über


LearningModelSession Konstruktoren

Definition

Überlädt

LearningModelSession(LearningModel)

Erstellt eine Sitzung mit dem Standardgerät.

LearningModelSession(LearningModel, LearningModelDevice)

Erstellt eine Sitzung mit dem angegebenen Gerät.

LearningModelSession(LearningModel, LearningModelDevice, LearningModelSessionOptions)

Erstellt eine Sitzung mit dem angegebenen Gerät und zusätzlichen Rückschlussoptionen.

LearningModelSession(LearningModel)

Erstellt eine Sitzung mit dem Standardgerät.

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

Parameter

model
LearningModel

Das trainierte Machine Learning-Modell für diese Sitzung.

Beispiele

Im folgenden Beispiel wird ein Modell geladen und damit eine Auswertungssitzung erstellt.

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

Hinweise

Windows Server

Um diese API unter Windows Server verwenden zu können, müssen Sie Windows Server 2019 mit Desktopdarstellung verwenden.

Threadsicherheit

Diese API ist threadsicher.

Gilt für:

LearningModelSession(LearningModel, LearningModelDevice)

Erstellt eine Sitzung mit dem angegebenen Gerät.

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)

Parameter

model
LearningModel

Das trainierte Machine Learning-Modell für diese Sitzung.

deviceToRunOn
LearningModelDevice

Das Auswertungsgerät der Sitzung.

Beispiele

Im folgenden Beispiel wird ein Modell geladen, das Gerät ausgewählt, auf dem das Modell ausgewertet werden soll, und eine Auswertungssitzung erstellt.

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

Hinweise

Windows Server

Um diese API unter Windows Server verwenden zu können, müssen Sie Windows Server 2019 mit Desktopdarstellung verwenden.

Threadsicherheit

Diese API ist threadsicher.

Gilt für:

LearningModelSession(LearningModel, LearningModelDevice, LearningModelSessionOptions)

Erstellt eine Sitzung mit dem angegebenen Gerät und zusätzlichen Rückschlussoptionen.

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)

Parameter

model
LearningModel

Das trainierte Machine Learning-Modell für diese Sitzung.

deviceToRunOn
LearningModelDevice

Das Auswertungsgerät der Sitzung.

learningModelSessionOptions
LearningModelSessionOptions

Die Optionen zum Konfigurieren der Sitzungserstellung und -auswertung.

Windows-Anforderungen

Gerätefamilie
Windows 10, version 1903 (eingeführt in 10.0.18362.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (eingeführt in v2.0)

Beispiele

Im folgenden Beispiel wird ein Modell geladen und eine Auswertungssitzung mithilfe von LearningModelSessionOptions konfiguriert.

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

Gilt für: