Share via


LearningModelDevice Kelas

Definisi

Perangkat yang digunakan untuk mengevaluasi model pembelajaran mesin.

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
Warisan
Object Platform::Object IInspectable LearningModelDevice
Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 10, version 1809 (diperkenalkan dalam 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (diperkenalkan dalam v1.0)

Contoh

Contoh berikut memuat model, memilih perangkat untuk mengevaluasi model, dan membuat sesi evaluasi.

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

Keterangan

Windows Server

Untuk menggunakan API ini di Windows Server, Anda harus menggunakan Windows Server 2019 dengan Pengalaman Desktop.

Keamanan utas

API ini aman untuk utas.

Konstruktor

LearningModelDevice(LearningModelDeviceKind)

Buat LearningModelDevice dari LearningModelDeviceKind yang ditentukan.

Properti

AdapterId

Mengembalikan pengidentifikasi unik untuk perangkat.

Direct3D11Device

Mengembalikan IDirect3DDevice untuk perangkat.

Metode

CreateFromDirect3D11Device(IDirect3DDevice)

Buat LearningModelDevice dari IDirect3DDevice yang ditentukan.

Berlaku untuk

Lihat juga