I am using ML.NET to import an ONNX model to do object detection. For the record, I exported the model from the CustomVision.ai site from Microsoft.
I inspected the model file in Netron and it clearly shows the input node as being named "data" and the output being named "model_outputs0".
However, when I try to run this line of code to apply the ONNX model
var pipeline = mlContext.Transforms.ApplyOnnxModel(modelFile: modelLocation, outputColumnNames: new[] { "model_outputs0" }, inputColumnNames: new[] { "data" }, gpuDeviceId: 0, fallbackToCpu: true);
// Fit scoring pipeline
var model = pipeline.Fit(data);
I get the following error:
Could not find input column 'data' Parameter name: inputSchema
Which clearly says that it cannot find the input column of data, even though I clearly see that is the name in Netron, as you can see:
Now, here is the part I really don't understand. When I was trying other output names, it has a different error which basically tells me it should actually be data:
Parameter name: Input tensor, image, does not exist in the ONNX model. Available input names are [data]. Actual value was image.
I run into the same issue and saw this post. After struggling a while I now found out that for me it worked to put this Input Column into the other Append functions - let me show it here
this was my code from official Microsoft documentation:
var pipeline = mlContext.Transforms.LoadImages(outputColumnName: "image", imageFolder: "", inputColumnName: nameof(ImageNetData.ImagePath))
.Append(mlContext.Transforms.ResizeImages(outputColumnName: "image", imageWidth: ImageNetSettings.imageWidth, imageHeight: ImageNetSettings.imageHeight, inputColumnName: "image"))
.Append(mlContext.Transforms.ExtractPixels(outputColumnName: "image"))
.Append(mlContext.Transforms.ApplyOnnxModel(modelFile: modelLocation, outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput }, inputColumnNames: new[] { TinyYoloModelSettings.ModelInput }));
ModelInput and ModelOutput was declared as const string and in the documentation there was the hint to find the values with Netron to replace it. But there are also .ResizeImages() and .LoadImages() and .ExtractPixels() - here it is the outputColumnName. For me it worked to configure it with the ModelInput value - for me that was "data" - I exported ONNX at customvision.ai
So now I run into another issue but I think this here has worked for me. So give it a chance
to be clear my changed code
var pipeline = mlContext.Transforms.LoadImages(outputColumnName: "data", imageFolder: "", inputColumnName: nameof(ImageNetData.ImagePath))
.Append(mlContext.Transforms.ResizeImages(outputColumnName: "data", imageWidth: ImageNetSettings.imageWidth, imageHeight: ImageNetSettings.imageHeight, inputColumnName: "data"))
.Append(mlContext.Transforms.ExtractPixels(outputColumnName: "data"))
.Append(mlContext.Transforms.ApplyOnnxModel(modelFile: modelLocation, outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput }, inputColumnNames: new[] { TinyYoloModelSettings.ModelInput }));
var model = pipeline.Fit(data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With