简体   繁体   English

如何使用 C#.NET 从头开始训练神经网络 model,然后在 ML.NET 中运行它?

[英]How to train a neural network model from scratch using C#.NET and then run it in ML.NET?

My biggest problem is that at this point many things related to binding TorchSharp and ML.NET are not completed, even though in many sources I saw that the work is in progress, but I hope to be able to overcome it somehow.我最大的问题是,此时许多与绑定 TorchSharp 和 ML.NET 相关的事情还没有完成,尽管在许多资源中我看到这项工作正在进行中,但我希望能够以某种方式克服它。 The main requirement is to use only C#.NET for training a very custom neural.network model from the scratch and then for running it.主要要求是仅使用 C#.NET 从头开始训练非常自定义的神经网络 model,然后运行它。 Please don't make emphasis on this requirement.请不要强调这个要求。 It is what it is.就是这样。 The question is how to train a model and then run it?问题是如何训练一个model然后运行呢?

So far, I managed to train a model using TorchSharp and save it with a hope to use it later in ML.NET but it looks like TorchSharp saves the model in a format very specific to torch/PyTorch/TorchSharp.到目前为止,我设法使用 TorchSharp 训练了一个 model 并保存它,希望以后在 ML.NET 中使用它,但看起来 TorchSharp 以非常特定于 torch/PyTorch/TorchSharp 的格式保存 model。 It looks like PyTorch has torch.onnx.export method but TorchSharp doesn't have such method.看起来 PyTorch 有 torch.onnx.export 方法,但 TorchSharp 没有这样的方法。 So, I'm stuck at a point how to save my trained model as ONNX?所以,我陷入了如何将训练有素的 model 保存为 ONNX 的问题?

Then I hope to be able to load/import that ONNX to ML.NET using OnnxTransformer and run it.然后我希望能够使用 OnnxTransformer 将 ONNX 加载/导入到 ML.NET 并运行它。 Any suggestions, keeping in mind that everything needs to be in C#.NET?任何建议,请记住一切都需要在 C#.NET 中? There is one other thing to add.还有一件事要补充。 I guess I can load and run the model using TorchSharp itself but there is already written code using ML.NET for running other models so I hoped to have a unified interface for running via ML.NET.我想我可以使用 TorchSharp 本身加载和运行 model,但是已经有使用 ML.NET 编写的代码来运行其他模型,所以我希望有一个统一的接口来通过 ML.NET 运行。

Being able to run models trained with TorchSharp in ML.NET is part of our roadmap .能够在 ML.NET 中运行使用 TorchSharp 训练的模型是我们路线图的一部分。 However, it's not something we'll be delivering in the near future (next 6-9 months).但是,我们不会在不久的将来(接下来的 6-9 个月)提供它。

I think in the short-term the best path forward is what you suggested:我认为在短期内最好的前进道路是你所建议的:

run the model using TorchSharp itself使用 TorchSharp 本身运行 model

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM