您的位置:首页 > 其它

Windows ML,系统内置的机器学习平台初探

2018-05-07 12:20 477 查看

人工智能现在很火,虽然最近风头隐隐有被区块链盖过,但仍是未来技术转型的首选方向之一。作为AI核心的机器学习,目前也进化到了可以基于平台自动训练模型的地步,例如Azure Machine Learning Service和Google AutoML Service。这使得训练模型的难度大大降低,开发人员可以分出更多精力关注在训练好的模型应用上。

在这种背景下,各个操作系统平台纷纷推出内置的机器学习框架/运行环境,iOS有CoreML,Android有TensorFlow。Windows在最近的RS4(build 1803)更新之后,也正式内置了机器学习平台- Windows ML

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  

 目前由于SDK仍在预览中,所以Visual Studio正式版并不会自动调用mlgen工具生成定义文件,需要手动执行如下命令:

mlgen -i INPUT-FILE -l LANGUAGE -n NAMESPACE [-o OUTPUT-FILE]
  • INPUT-FILE
    : ONNX模型文件
  • LANGUAGE
    : C++或者C#
  • NAMESPACE
    : 命名空间
  • OUTPUT-FILE
    : 输出路径,可缺省

 

 总结

 

有了Windows ML后我们可以实现以前难以实现的机器学习特性,同时不用依赖外部web service,很多创新的体验可以实现,不仅仅是在PC,甚至在HoloLens上同样可以运用机器学习的能力。

最后给大家安利下我的开源项目- Awesome WindowsML ONNX Models ,这个项目除了提供我已经验证过的模型外,还提供了CoreML模型的快速转换工具。

 

 

 同时我也在开发为HoloLens编写的Demo,最近将会和大家见面

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: