人工智能现在很火, 虽然最近风头隐隐有被区块链盖过, 但仍是未来技术转型的首选方向之一. 作为 AI 核心的机器学习, 目前也进化到了可以基于平台自动训练模型的地步, 例如 Azure Machine Learning Service 和 Google AutoML Service. 这使得训练模型的难度大大降低, 开发人员可以分出更多精力关注在训练好的模型应用上.
在这种背景下, 各个操作系统平台纷纷推出内置的机器学习框架 / 运行环境, iOS 有 CoreML,Android 有 TensorFlow.Windows 在最近的 RS4(build 1803) 更新之后, 也正式内置了机器学习平台 - Windows ML.
Windows ML 是什么?
Windows ML 是 Windows 全新的内置机器学习平台, 用于本机执行预训练的机器学习模型, 并提供了 API 允许我们快速集成到应用中.
它的亮点如下:
支持硬件加速
在兼容 DirectX 12 的设备上可以直接使用 GPU 加速运算, 确保机器学习模型可以被高效执行.
本机执行
不依赖于任何远程服务, 不受任何网络连接限制, 本机即可达到低延迟高性能的执行效果.
图像处理优化
针对计算机视觉场景, 对视频, 图像和相机数据统一预处理为 VideoFrame 形式, 简化图像处理流程.
模型要求
Windows ML 目前仅支持执行 ONNX 格式模型, 其他格式需要预先转换后再使用.
ONNX 是由微软, Facebook 和英特尔等公司推出的一个通用开放的机器学习模型格式, 官方支持现有机器学习框架对其转换. ONNX 项目地址 https://github.com/onnx/onnx
- Core ML
- Scikit-Learn
- XGBoost
- LibSVM
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using Windows.Media;
- using Windows.Storage;
- using Windows.AI.MachineLearning.Preview;
- // FNSLaMuse
- namespace Demo
- {
- public sealed class FNSLaMuseModelInput
- {
- public VideoFrame inputImage { get; set; }
- }
- public sealed class FNSLaMuseModelOutput
- {
- public VideoFrame outputImage { get; set; }
- public FNSLaMuseModelOutput()
- {
- this.outputImage = VideoFrame.CreateWithSoftwareBitmap(new Windows.Graphics.Imaging.SoftwareBitmap(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, 720, 720));
- }
- }
- public sealed class FNSLaMuseModel
- {
- private LearningModelPreview learningModel;
- public static async Task<FNSLaMuseModel> CreateFNSLaMuseModel(StorageFile file)
- {
- LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);
- FNSLaMuseModel model = new FNSLaMuseModel();
- model.learningModel = learningModel;
- return model;
- }
- public async Task<FNSLaMuseModelOutput> EvaluateAsync(FNSLaMuseModelInput input) {
- FNSLaMuseModelOutput output = new FNSLaMuseModelOutput();
- LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel);
- binding.Bind("inputImage", input.inputImage);
- binding.Bind("outputImage", output.outputImage);
- LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty);
- return output;
- }
- }
- }
- View Code
来源: https://www.cnblogs.com/mantgh/p/9002027.html