A comprehensive Windows Machine Learning (WinML) demonstration application that showcases ONNX model inference across different execution providers and hardware accelerators.
This WPF application demonstrates how to deploy and optimize machine learning models on Windows using various execution providers. It features a user-friendly interface for managing execution providers, compiling models for specific hardware, and running image classification with real-time performance metrics.
- Dynamic EP Discovery: Automatically detects available execution providers
- Hardware Acceleration: Support for CPU, GPU, and specialized AI accelerators
- EP Initialization: Download and register WinML execution providers
- Real-time Status: Live monitoring of EP availability and capabilities
- Multi-format Support: JPG, PNG, BMP image formats
- Live Preview: Real-time image preview with automatic resizing
- Batch Processing: Process multiple images sequentially
- Top-5 Results: Display confidence scores for top predictions
- Hardware-Specific Compilation: Compile ONNX models for target hardware
- Performance Tuning: Optimize for different execution providers
- Memory Management: Efficient model loading and session management
- Real-time Metrics: Inference time, compilation time, loading time
- Console Logging: Detailed operation logs with timestamps
- Error Handling: Comprehensive error reporting and recovery
WinMLLabDemo/
βββ MainWindow.xaml/.cs # Main UI and event handling
βββ ExecutionLogic.cs # ML runtime and EP management
βββ ModelHelpers.cs # Image processing and model utilities
βββ SqueezeNet.onnx # Pre-trained image classification model
βββ SqueezeNet.Labels.txt # 1000 ImageNet class labels
βββ image.jpg, image2.png # Sample test images
| Provider | Description | Use Case |
|---|---|---|
| CPUExecutionProvider | CPU-based inference | Universal compatibility |
| DmlExecutionProvider | DirectML GPU acceleration | Windows GPU optimization |
| OpenVINOExecutionProvider | Intel OpenVINO optimization | Intel CPU/GPU acceleration |
| QNNExecutionProvider | Qualcomm Neural Network | Snapdragon AI acceleration |
| VitisAIExecutionProvider | Xilinx Vitis AI | FPGA acceleration |
| NvTensorRTRTXExecutionProvider | NVIDIA TensorRT | NVIDIA GPU optimization |
- Windows 10/11 (version 10.0.26100.0 or later)
- .NET 8.0 or later
- Visual Studio 2022 (recommended) or VS Code
- Windows App SDK (included in project)
-
Clone the repository
git clone <repository-url> cd WinMLLabDemo
-
Build the project
dotnet build
-
Run the application
dotnet run
- Launch the application
- Initialize WinML EPs (if not already done)
- Click "Initialize WinML EPs" button
- Wait for download and registration to complete
- Select an execution provider from the left panel
- Choose a sample image or browse for your own
- Compile the model for your selected EP (if needed)
- Load the model and run classification
βββββββββββββββββββββββββββββββββββββββ
β Execution Providers β
βββββββββββββββββββββββββββββββββββββββ€
β [Refresh List] [Initialize WinML] β
β β
β βββββββββββ¬ββββββββββ¬ββββββββββββββ β
β β Name β Vendor β Device Type β β
β βββββββββββΌββββββββββΌββββββββββββββ€ β
β β CPU EP β ONNX β CPU β β
β β DML EP β MS β GPU β β
β βββββββββββ΄ββββββββββ΄ββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ
- Click "Browse..." to select an image file
- Supported formats: JPG, PNG, BMP
- Preview appears automatically
- Sample images included:
image.jpg,image2.png
βββββββββββββββββββββββββββββββββββββββ
β [Compile Model] [Load Model] [Run] β
βββββββββββββββββββββββββββββββββββββββ
- Compile Model: Optimizes ONNX model for selected EP
- Load Model: Loads compiled model into memory
- Run Classification: Executes inference and displays results
Top Predictions:
-------------------------------------------
Label Confidence
-------------------------------------------
golden retriever 95.23%
Labrador retriever 3.45%
tennis ball 1.12%
-------------------------------------------
- Threading Configuration: OpenVINO EP supports custom thread count
- Performance Mode: QNN EP supports high-performance mode
- Memory Management: Automatic cleanup of inference sessions
- Graceful Degradation: Falls back to CPU if GPU unavailable
- Detailed Logging: Comprehensive error messages in console
- Recovery Options: Automatic retry mechanisms
- Model: SqueezeNet v1.1
- Architecture: Lightweight CNN optimized for mobile/edge
- Input Size: 224Γ224Γ3 (RGB)
- Output: 1000-class classification (ImageNet)
- Model Size: ~5MB (compressed)
graph LR
A[Input Image] --> B[Load & Decode]
B --> C[Resize to 224x224]
C --> D[Convert to BGRA8]
D --> E[Normalize RGB]
E --> F[Apply Mean/Std]
F --> G[Create Tensor]
G --> H[Model Inference]
H --> I[Softmax]
I --> J[Top-5 Results]
| Execution Provider | Typical Latency | Memory Usage | Optimization |
|---|---|---|---|
| CPU EP | 50-200ms | Low | Baseline |
| DML EP | 10-50ms | Medium | GPU acceleration |
| OpenVINO EP | 20-80ms | Low | Intel optimization |
| QNN EP | 5-30ms | Low | Snapdragon AI |
| TensorRT EP | 5-25ms | High | NVIDIA optimization |
WinMLLabDemo/
βββ App.xaml/.cs # Application entry point
βββ MainWindow.xaml/.cs # Main UI and event handling
βββ ExecutionLogic.cs # Core ML operations
βββ ModelHelpers.cs # Image processing utilities
βββ AssemblyInfo.cs # Assembly metadata
βββ SqueezeNet.onnx # Pre-trained model
βββ SqueezeNet.Labels.txt # Class labels
βββ image.jpg # Sample image 1
βββ image2.png # Sample image 2
βββ WinMLLabDemo.csproj # Project configuration
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.8.250702007-experimental4" />- Target Framework: .NET 8.0-windows10.0.26100.0
- Platforms: win-x86, win-x64, win-arm64
- UI Framework: WPF (Windows Presentation Foundation)
- ML Runtime: ONNX Runtime with WinML integration
- Install Visual Studio 2022 with .NET desktop development workload
- Clone and open the solution in Visual Studio
- Restore NuGet packages
- Build and run the project
image.jpg: Microsoft Azure branding imageimage2.png: Additional test image
When running classification on the sample images, you should see:
- Top predictions with confidence scores
- Performance metrics in console output
- Real-time logging of operations
- Baseline: Run with CPU EP for comparison
- GPU Testing: Test with DML EP for acceleration
- Specialized Hardware: Test with vendor-specific EPs
- Memory Monitoring: Check console for memory usage
- Solution: Click "Initialize WinML EPs" button
- Check: Windows version compatibility
- Verify: .NET 8.0 installation
- Solution: Ensure sufficient disk space
- Check: EP compatibility with your hardware
- Verify: ONNX model file integrity
- Solution: Check file format and path
- Supported: JPG, PNG, BMP formats
- Verify: File permissions and accessibility
- Solution: Try CPU EP as fallback
- Check: Hardware compatibility
- Verify: Model compilation success
Enable detailed logging by checking console output for:
- EP initialization status
- Model compilation progress
- Inference timing metrics
- Memory usage statistics
- ONNX: Open Neural Network Exchange
- SqueezeNet: Model Architecture Paper
- ImageNet: Dataset Information
- Follow existing code style and patterns
- Add comprehensive error handling for new features
- Update documentation for any API changes
- Test across different execution providers
- Include performance metrics for optimizations
- Test with all supported execution providers
- Verify image processing pipeline
- Check memory usage patterns
- Validate error handling scenarios
- Test performance on different hardware
This project is licensed under the MIT License - see the LICENSE file for details.
- Microsoft WinML Team for the Windows Machine Learning framework
- ONNX Runtime Team for the cross-platform ML runtime
- SqueezeNet Authors for the lightweight CNN architecture
- ImageNet Team for the comprehensive image classification dataset
Note: This demo application is designed for educational and development purposes. For production use, consider additional security, performance, and reliability requirements.