Can't get input column name of ONNX model to work
Asked Answered
T

2

6

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:

enter image description here

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.

Tsar answered 30/7, 2019 at 5:31 Comment(1)
Hi, Is there a solution for this problem? Have been facing the same issue.Blacklist
B
1

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);
Bannerol answered 8/4, 2021 at 20:55 Comment(0)
T
-2

Same issue: System.ArgumentOutOfRangeException: Could not find input column 'data' Parameter name: inputSchema

Model is exportet from CustomVision.ai

Netron shows inputparameter names as "data"

Ternary answered 12/8, 2019 at 11:55 Comment(1)
does anyone solved this? I have a same issue. the model is exported with keras2onnx which shows the input paramter names as "input_1"Dumbwaiter

© 2022 - 2024 — McMap. All rights reserved.