Important
Some information relates to prerelease product that may be substantially modified before itâs released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
The device used to evaluate the machine learning model.
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
Windows 10, version 1809 (introduced in 10.0.17763.0)
Windows.AI.MachineLearning.MachineLearningContract (introduced in v1.0)
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;
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;
}
}
Remarks Windows Server
To use this API on Windows Server, you must use Windows Server 2019 with Desktop Experience.
Thread safetyThis API is thread-safe.
Constructors Properties Methods See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4