This sample demonstrates how to integrate Windows Machine Learning (WinML) into an Electron application using the Windows App Development CLI. The app uses the SqueezeNet 1.1 model to classify images directly on the user's device, and the Phi model for text generation.
- Image Classification: Uses SqueezeNet 1.1 ONNX model for real-time image classification
- C# Native Addon: A .NET 10 Native AOT addon that bridges JavaScript and WinML APIs
- Hardware Acceleration: Automatically uses CPU, GPU, or NPU based on device capabilities
- Production Ready: Includes MSIX packaging configuration and ASAR handling for distribution
- 🖼️ Classify Images: Select any image and get top predictions with confidence scores
- ⚡ Fast Performance: Native AOT compilation with hardware acceleration
- 📦 MSIX Packaging: Ready for distribution via Microsoft Store or direct download
- 🎨 Modern UI: Simple, clean interface for testing image classification
- Windows 11 or Windows 10 (version 1809+)
- Node.js -
winget install OpenJS.NodeJS --source winget - .NET SDK v10 -
winget install Microsoft.DotNet.SDK.10 --source winget - Visual Studio with the Native Desktop Workload -
winget install --id Microsoft.VisualStudio.Community --source winget --override "--add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --passive --wait"
npm installThis automatically runs the postinstall script which:
- Restores Windows SDK packages to
.winapp/ - Generates a development certificate
- Adds debug identity to Electron
The models are available in the AI Dev Gallery. Install the gallery to download the models. You don't need both models if you only care about one or the other. The models folder will need to be created.
- Navigate to the Classify Image sample
- Download the SqueezeNet 1.1 model
- Click Open Containing Folder to locate the
.onnxfile - Copy
squeezenet1.1-7.onnxto themodels/folder in this project
- Navigate to the Generate Text sample
- Download any of the Phi models from Custom models
- Click Open Containing Folder to locate model files
- Copy all the contents of the folder (should have .onnx and .json files) to the
models/phifolder in this project.
npm run build-winMlAddonThis compiles the C# addon using Native AOT, creating a .node binary that requires no .NET runtime on target machines.
npm startNote: If you encounter a blank window or crash, add
--no-sandboxto the start script inpackage.jsonas a workaround for a known Windows issue.
- Full Guide - Step-by-step tutorial
- winapp CLI Documentation - CLI reference
- WinML Documentation - Official WinML docs
- AI Dev Gallery
App crashes or shows blank window:
Add -- --no-sandbox to the start script in package.json.
Model not found:
Ensure squeezenet1.1-7.onnx is in the models/ folder.
Build errors:
Run npx winapp restore to restore SDK packages.
Certificate errors:
Reinstall the certificate (as admin): npx winapp cert install .\devcert.pfx
See LICENSE for details.