README 顶部提示旧版 Windows.AI.MachineLearning API 已被 Windows App SDK 中的 Microsoft.Windows.AI.MachineLearning 取代;In-Box 方式需 Windows 10 Build 17763 (RS5) 或更新,NuGet 方式支持 Windows 8.1 但部分 API(如 VideoFrame)在旧系统不可用;示例依赖 ONNX 模型文件,需按各示例说明另行获取

Windows-Machine-Learning
microsoftMIT长期未更新微软 Windows ML 的官方示例与工具集,帮助开发者在 Windows 上加载 ONNX 模型并调用系统内置的机器学习推理能力。
Samples and Tools for Windows ML.
安装 Visual Studio 2017 15.7.4 或更新版本,然后克隆仓库并打开对应示例工程README 未说明具体显存或 GPU 型号要求;示例面向 Windows 平台,推理由 ONNX Runtime 与 DirectML 驱动。
微软官方 Windows ML 示例与工具集,演示如何在 Windows 应用里集成 ONNX 模型推理
微软 Windows ML 的官方示例与工具集,帮助开发者在 Windows 上加载 ONNX 模型并调用系统内置的机器学习推理能力。
核心能力
- 提供图像分类、风格迁移等场景的完整示例代码
- 覆盖 UWP 与桌面应用,支持 C#、C++/WinRT、Rust 等语言
- 包含 WinmlRunner 与 WinML Dashboard 等开发者工具
- 演示自定义张量化、自定义 CPU 算子与设备适配器选择
- 基于 ONNX Runtime 与 DirectML 提供低延迟推理
容易踩的坑
- v1.3.0WinMLRunner v1.3.0最新正式版2022-06-30 · 2022-06-30 19:11 UTC
General
- Diagnostic warnings are emitted when operators fallback to CPU when the caller specified GPU.
- New -logCPUFallback command line argument added. This argument will output addition information about why CPU fallback occured.
Dependencies
- DirectML version bumped to 1.8.2.
- Microsoft.AI.MachineLearning version bumped to 1.11.
- OnnxRuntime version bumped to 1.11.
- v1.2.2WinMLRunner v1.2.22020-09-10 · 2020-09-10 00:10 UTC
查看更新说明
This change removes the ability of WinMLRunner.exe to load Windows.AI.MachineLearning.dll locally if the DLL is within the same directory as the executable. Instead, MicrosoftMLRunner.exe should be used for loading Microsoft.AI.MachineLearning.dll within the same directory. More details below.
Using Microsoft.AI.Machinelearning NuGet
MicrosoftMLRunner.exe uses
Microsoft.AI.MachineLearning.dllin the immediate directory of the executable instead of loadingWindows.AI.MachineLearning.dllfrom System32 (that is for WinMLRunner). MicrosoftMLRunner is useful to compare performance with an older version of WinML or to test a newer version of WinML's NuGet. For more information, please reference Microsoft.AI.MachineLearning NuGet page. - 1.2.1.2WinMLRunner v1.2.1.22020-07-13 · 2020-07-13 23:28 UTC
查看更新说明
- v0.7.0WinML Dashboard v0.7.02020-03-03 · 2020-03-03 01:32 UTC
查看更新说明
- Support to convert to opset10 models
- Updated WinMLRunner
- 1.2.1.1WinMLRunner v1.2.1.12019-08-29 · 2019-08-29 23:08 UTC
查看更新说明
New Features:
-
-Tensor [function] : load the input as a tensor, with optional function for input preprocessing
- Optional function arguments:
- Identity(default) : No input transformations will be performed
- Normalize : float scale factor and comma separated per channel means and stddev for normalization.
- Optional function arguments:
-
Example Usage:
-
WinMLRunner.exe -model ./densenet121.onnx -Tensor Normalize 255 0.485,0.456,0.406 0.229,0.224,0.225 -CPU -SaveTensorData First -PerIterationPath <tensorDataPath>
-
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Windows Machine Learning
⚠️ IMPORTANTFor the latest documentation about Windows Machine Learning, see What is Windows ML. That documentation describes APIs that are in the Microsoft.Windows.AI.MachineLearning namespace, which ships in the Windows App SDK. Those APIs supersede the ones documented here, which are in the Windows.AI.MachineLearning namespace, and were shipped in 2018.
Windows Machine Learning is a high-performance machine learning inference API that is powered by ONNX Runtime and DirectML.
The Windows ML API is a Windows Runtime Component and is suitable for high-performance, low-latency applications such as frameworks, games, and other real-time applications as well as applications built with high-level languages.
This repo contains Windows Machine Learning samples and tools that demonstrate how to build machine learning powered scenarios into Windows applications.
- Getting Started with Windows ML
- Model Samples
- Advanced Scenario Samples
- Developer Tools
- Feedback
- External Links
- Contributing
For additional information on Windows ML, including step-by-step tutorials and how-to guides, please visit the Windows ML documentation.
| Sample/Tool | Status |
|---|---|
| All Samples | |
| WinmlRunner | |
| WinML Dashboard |
Getting Started with Windows ML
Prerequisites
Windows ML offers machine learning inferencing via the inbox Windows SDK as well as a redistributable NuGet package. The table below highlights the availability, distribution, language support, servicing, and forward compatibility aspects of the In-Box and NuGet package for Windows ML.
| In-Box | NuGet | |
|---|---|---|
| Availability | Windows 10 - Build 17763 (RS5) or NewerFor more detailed information about version support, checkout our docs. | Windows 8.1 or NewerNOTE: Some APIs (ie: VideoFrame) are not available on older OSes. |
| Windows SDK | Windows SDK - Build 17763 (RS5) or Newer | Windows SDK - Build 17763 (RS5) or Newer |
| Distribution | Built into Windows | Package and distribute as part of your application |
| Servicing | Microsoft-driven (customers benefit automatically) | Developer-driven |
| Forward | compatibility Automatically rolls forward with new features | Developer needs to update package manually |
Learn more here.
Model Samples
In this section you will find various model samples for a variety of scenarios across the different Windows ML API offerings.
Image Classification
A subdomain of computer vision in which an algorithm looks at an image and assigns it a tag from a collection of predefined tags or categories that it has been trained on.
Style Transfer
A computer vision technique that allows us to recompose the content of an image in the style of another.
| Windows App Type Distribution | UWPIn-Box | UWPNuGet | DesktopIn-Box | DesktopNuGet |
|---|---|---|---|---|
| FNSCandy | ✔️C# - FNS Style Transfer✔️C# - Real-Time Style Transfer |
Advanced Scenario Samples
These advanced samples show how to use various binding and evaluation features in Windows ML:
-
Custom Tensorization: A Windows Console Application (C++/WinRT) that shows how to do custom tensorization.
-
Custom Operator (CPU): A desktop app that defines multiple custom cpu operators. One of these is a debug operator which we invite you to integrate into your own workflow.
-
Adapter Selection: A desktop app that demonstrates how to choose a specific device adapter for running your model.
-
Plane Identifier: a UWP app and a WPF app packaged with the Desktop Bridge, sharing the same model trained using Azure Custom Vision service. For step-by-step instructions for this sample, please see the blog post Upgrade your WinML application to the latest bits.
-
Custom Vision and Windows ML: The tutorial shows how to train a neural network model to classify images of food using Azure Custom Vision service, export the model to ONNX format, and deploy the model in a Windows Machine Learning application running locally on Windows device.
-
ML.NET and Windows ML: This tutorial shows you how to train a neural network model to classify images of food using ML.NET Model Builder, export the model to ONNX format, and deploy the model in a Windows Machine Learning application running locally on a Windows device.
-
PyTorch Data Analysis: The tutorial shows how to solve a classification task with a neural network using the PyTorch library, export the model to ONNX format and deploy the model with the Windows Machine Learning application that can run on any Windows device.
-
PyTorch Image Classification: The tutorial shows how to train an image classification neural network model using PyTorch, export the model to the ONNX format, and deploy it in a Windows Machine Learning application running locally on your Windows device.
-
YoloV4 Object Detection: This tutorial shows how to build a UWP C# app that uses the YOLOv4 model to detect objects in video streams.
Developer Tools
-
Model Conversion
Windows ML provides inferencing capabilities powered by the ONNX Runtime engine. As such, all models run in Windows ML must be converted to the ONNX Model format. Models built and trained in source frameworks like TensorFlow or PyTorch must be converted to ONNX. Check out the documentation for how to convert to an ONNX model:
- https://onnxruntime.ai/docs/tutorials/mobile/model-conversion.html
- https://docs.microsoft.com/en-us/windows/ai/windows-ml/tutorials/pytorch-convert-model
- WinMLTools: a Python tool for converting models from different machine learning toolkits into ONNX for use with Windows ML.
-
Model Optimization
Models may need further optimizations applied post conversion to support advanced features like batching and quantization. Check out the following tools for optimizing your model:
-
WinML Dashboard (Preview): a GUI-based tool for viewing, editing, converting, and validating machine learning models for Windows ML inference engine. This tool can be used to enable free dimensions on models that were built with fixed dimensions. Download Preview Version
-
Graph Optimizations: Graph optimizations are essentially graph-level transformations, ranging from small graph simplifications and node eliminations to more complex node fusions and layout optimizations.
-
Graph Quantization: Quantization in ONNX Runtime refers to 8 bit linear quantization of an ONNX model.
-
-
Model Validation
-
WinMLRunner: a command-line tool that can run .onnx or .pb models where the input and output variables are tensors or images. It is a very handy tool to quickly validate an ONNX model. It will attempt to load, bind, and evaluate a model and print out helpful messages. It also captures performance measurements.
-
-
Model Integration
-
WinML Code Generator (mlgen): a Visual Studio extension to help you get started using WinML APIs on UWP apps by generating a template code when you add a trained ONNX file into the UWP project. From the template code you can load a model, create a session, bind inputs, and evaluate with wrapper codes. See docs for more info.
-
WinML Samples Gallery: explore a variety of ML integration scenarios and models.
-
Check out the Model Samples and Advanced Scenario Samples to learn how to use Windows ML in your application.
-
Feedback
- For issues, file a bug on GitHub Issues.
- Ask questions on Stack Overflow.
- Vote for popular feature requests on Windows Developer Feedback or include your own request.
External Links
- ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator.
- ONNX: Open Neural Network Exchange Project.
Contributing
We're always looking for your help to fix bugs and improve the samples. Create a pull request, and we'll be happy to take a look.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
