Contact Us0Items in cart£0.00

Windows.ai.machinelearning Here

// Run inference var results = await session.EvaluateAsync(binding, "runId");

// 1. Preprocess: resize to model input size (224x224) var resized = await ImageHelper.ResizeBitmap(bitmap, 224, 224); // 2. Convert to float tensor (channel-first, normalized) var tensor = ImageHelper.BitmapToTensor(resized);

mldata.exe model.onnx /namespace MyApp.ML /output ModelCode.cs windows.ai.machinelearning

var session = new LearningModelSession(model, device);

var info = LearningModelDevice.FindAllDevices(); foreach (var d in info) Console.WriteLine(d.AdapterId); | Model Type | Input Shape | Output Shape | |------------|-------------|---------------| | Image classification | [1,3,224,224] | [1,1000] | | Object detection (YOLO) | [1,3,640,640] | [1,84,8400] | | BERT text | [1,128] (ids) + [1,128] (mask) | [1,2] (logits) | 7. Debugging & Performance Enable diagnostics: // Run inference var results = await session

using Microsoft.ML.OnnxRuntime; using Microsoft.AI.MachineLearning; // Load model var file = await StorageFile.GetFileFromApplicationUriAsync( new Uri("ms-appx:///Assets/model.onnx")); var model = await LearningModel.LoadFromStorageFileAsync(file); // Create session var session = new LearningModelSession(model, new LearningModelDevice(LearningModelDeviceKind.Default)); // Create binding var binding = new LearningModelBinding(session);

// Get output var outputTensor = results.Outputs["output"] as TensorFloat; var outputArray = outputTensor.GetAsVectorView(); public async Task<string> ClassifyImage(SoftwareBitmap bitmap) Map to label return Labels[ArgMax(classId)]

// 4. Bind & evaluate var session = new LearningModelSession(model); var binding = new LearningModelBinding(session); binding.Bind("data", tensor);

// 3. Load model (cache globally) var model = await App.ModelLoader.GetModelAsync();

// 5. Map to label return Labels[ArgMax(classId)]; Windows ML automatically uses DirectML – you don’t need to change code. But you can select the device:

Join the LR VIP club

Receive exclusive offers, coupons and more direct to your inbox.