Search code examples
c#.net.net-coreml.netonnx

How insert data in an ONNX as float32[N,60,1] in ML.NET


I'm using ML.NET and I want to insert as input a float32[N, 60, 1](as in the picture). I don't figure how to pass the data. I'm trying with this class:

public class OnnxInput
{
    [ColumnName("lstm_input")]
    public float lstm_input { get; set; }
}

var input = new OnnxInput[length][];

// Here I load the data into the input variable

var dataView = mlContext.Data.LoadFromEnumerable(input);
var pipeline = mlContext.Transforms.
            ApplyOnnxModel(
                    modelFile: modelLocation,
                    inputColumnNames: new[] { TinyYoloModelSettings.ModelInput },
                    outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput }
                );
var model = pipeline.Fit(data);

creating this matrix, when I try to fit the data into the pipeline I have the error: System.ArgumentOutOfRangeException: 'Could not determine an IDataView type and registered custom types for member SyncRoot (Parameter 'rawType')'

Trying with another approach, with this input class:

public class OnnxInput
{
    [ColumnName("lstm_input")]
    public float[] lstm_input { get; set; }
}

var input = new OnnxInput[realLength];

// Here I load the data into the input variable

var dataView = mlContext.Data.LoadFromEnumerable(input);
var pipeline = mlContext.Transforms.
            ApplyOnnxModel(
                    modelFile: modelLocation,
                    inputColumnNames: new[] { TinyYoloModelSettings.ModelInput },
                    outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput }
                );
var model = pipeline.Fit(data);

creating this matrix, when I try to fit the data into the pipeline I have the error: System.InvalidOperationException: 'Variable length input columns not supported'

enter image description here


Solution

  • The variable input error (Variable length input columns not supported) just means your model is expecting a fixed sized input. Specifically, you can add the attribute [VectorType(60, 1)] on top of the property lstm_input in OnnxInput class.