Skip to content

Error on prediction with LSTM Model in ONNX Format in ML.Net #5273

Closed
@ladislav-dolezal

Description

@ladislav-dolezal

System information

  • Windows 10
  • .NET Core 3.1, Microsoft.ML 1.5.0, Microsoft.ML.OnnxRuntime 1.3.0, Microsoft.ML.OnnxTransformer 1.5.0

Issue

I would like to predict Values with my LSTM Model in ONNX Format. I am struggling on data input for my ONNX Model in my ML.NET project. When I run my code, I get an Exception: System.NullReferenceException: 'Object reference not set to an instance of an object.' on prediction. The input data is just dummy. I am trying to find out, how to input data in form (None,3,7) as expected from LSTM Model. LSTM Model ist attached. Can someone help me, what I am doing wrong?
Why I get exception or how to deliver data for my ONNX Model.

using Microsoft.ML;
using Microsoft.ML.Data;
using System;
using System.Data.SqlClient;

namespace InQu.ML.Test.ONNX.FehlerAbschätzungLSTM
{
    class Program
    {
        static void Main(string[] args)
        {
            var mlContext = new MLContext();
            
            var x = new InputData[] { 
                        new InputData() { X = new float[,] { { 1, 2, 3, 4, 5, 6, 7 }, { 1, 2, 3, 4, 5, 6, 7 }, { 1, 2, 3, 4, 5, 6, 7 } } }                       
                    };

            IDataView dataView = mlContext.Data.LoadFromEnumerable<InputData>(x);

            var pipeline = mlContext.Transforms.ApplyOnnxModel(modelFile: @".\scikit-learn\AbschatzungFehlerLSTM.onnx", 
                            inputColumnNames: new[] { "input_layer",  }, 
                            outputColumnNames: new[] { "dense_3" });

            var model = pipeline.Fit(dataView);
            
            var predEngine = mlContext.Model.CreatePredictionEngine<InputData, OutputData>(model);

            OutputData prediction = new OutputData() { y = new float[0] };
            predEngine.Predict(x[0], ref prediction);
        }
    }

    public class InputData
    {
        [ColumnName("input_layer")]
        [VectorType(3,7)]
        public float[,] X { get; set; }        
    }

    public class OutputData
    {
        [ColumnName("dense_3")]
        [VectorType(1)]
        public float[] y { get; set; }
    }
}

Metadata

Metadata

Assignees

Labels

Awaiting User InputAwaiting author to supply further info (data, model, repro). Will close issue if no more info given.P3Doc bugs, questions, minor issues, etc.onnxExporting ONNX models or loading ONNX modelsquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions