Using a model created from python in ML.NET
Asked Answered
M

1

5

We have a scenario where we need to use Machine learning algorithm to predict a value. We want to do it in ML.NET because of some issues.

We tried AutoML in a project and trained it with almost 80k records of data. We trained the data for more than 30 min. The csv file was 22MB. Data looks like below.

------------------------------------
Col1                        col2
------------------------------------
Some text                    21
Some other text               2

We have some historic data of above kind. We need to predict col2 from the col1 text. It is predicting the result in decimals even though the column is whole number.

There is a model created by someone in python which is working as expected for now. We want to use it in ML.NET.

Is there any possibility we can use a model created from python, in ML.NET?

Mussel answered 4/3, 2021 at 19:37 Comment(0)
W
11

There are a couple of ways depending if it's a Tensorflow model or if it's from another framework.

If it's a Tensorflow model, it can be loaded directly using the mlContext.Model.LoadTensorFlowModel method from the Microsoft.ML.TensorFlow package.

var tensorFlowModel = context.Model.LoadTensorFlowModel(_modelPath);

If it's any other model, like a Keras or PyTorch model, then it can be converted to the ONNX format using one of the ONNX converter packages. Here's a list of how to do this with several different formats.

Once you have an ONNX model, you can use the Microsoft.ML.OnnxTransformer package which will give you an ApplyOnnxModel method.

mlContext.Transforms.ApplyOnnxModel(modelFile: "Model File", outputColumnName: "Output column name", inputColumnName: "Input column name")
Want answered 5/3, 2021 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.