I'm trying to make previsions with a ONNX model in a C# console application with ML.NET I'm getting the message: System.ArgumentException: 'Length of memory (10) must match product of dimensions (0).'
This is what I got so far:
Output and input:
public class BertInput
{
[VectorType(1, 256)]
[ColumnName("input_ids")]
public Int64[] InputIds { get; set; }
[VectorType(1, 256)]
[ColumnName("attention_mask")]
public Int64[] AttentionMask { get; set; }
[VectorType(1, 256)]
[ColumnName("token_type_ids")]
public Int64[] TokenTypeIds { get; set; }
}
public class BertOutput
{
[ColumnName("logits")]
public float[] Logits { get; set; }
}
My program.cs so far:
[class Program
{
static string ONNX_MODEL_PATH = "C:\\Users\\t203951\\source\\repos\\AutoMLONNXConsoleApp\\Assets\\Model\\model.onnx";
static void Main(string\[\] args)
{
MLContext mlContext = new MLContext();
var onnxPredictionPipeline = GetPredictionPipeline(mlContext);
var onnxPredictionEngine = mlContext.Model.CreatePredictionEngine<BertInput, BertOutput>(onnxPredictionPipeline);
var testInput = new BertInput
{
InputIds = (\[101, 7592, 1010, 2026, 3899, 2003, 10140, 102, 0, 0\]),
AttentionMask = (\[1, 1, 1, 1, 1, 1, 1, 1, 0, 0\]),
TokenTypeIds = (\[0, 0, 0, 0, 0, 0, 0, 0, 0, 0\])
};
var prediction = onnxPredictionEngine.Predict(testInput);
Console.WriteLine($"Predicted Fare: {prediction.Logits.First()}");
static ITransformer GetPredictionPipeline(MLContext mlContext)
{
var inputColumns = new string\[\] { "input_ids", "attention_mask", "token_type_ids" };
var outputColumns = new string\[\] { "logits" };
var onnxPredictionPipeline =
mlContext
.Transforms
.ApplyOnnxModel(
outputColumnNames: outputColumns,
inputColumnNames: inputColumns,
ONNX_MODEL_PATH);
var emptyDv = mlContext.Data.LoadFromEnumerable(new BertInput\[\] { });
return onnxPredictionPipeline.Fit(emptyDv);
}
}
}][1]
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744945878a4602613.html
评论列表(0条)