Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input Shape Mismatch #18421

Closed
gktval opened this issue Nov 14, 2023 · 1 comment
Closed

Input Shape Mismatch #18421

gktval opened this issue Nov 14, 2023 · 1 comment
Labels
ep:CUDA issues related to the CUDA execution provider platform:windows issues related to the Windows platform

Comments

@gktval
Copy link

gktval commented Nov 14, 2023

Describe the issue

I have an image classification model that was created in python. I am trying to load the onnx model in c#, but am running into errors. The image data the model was created on was 4 channel 256x256 images. When loading the model, the shape is correct, but the data length seems to be only 3 channel rgb instead of rgba (i.e. 256x256x3 = 196608). Here is the error:

System.InvalidOperationException: 'Input shape mismatch: Input 'sequential_input' has shape 1,256,256,4, but input data is of length 196608.'

Here is the code for loading the model:

var pipeline = mlContext.Transforms
.ResizeImages("image", 256, 256, inputColumnName: "sequential_input")
.Append(mlContext.Transforms.ExtractPixels("sequential_input", "image"))
.Append(mlContext.Transforms.ApplyOnnxModel("dense_1", "sequential_input", ONNX_MODEL_PATH, gpuDeviceId: 0));

var emptyDv = mlContext.Data.LoadFromEnumerable(new OnnxInput[] { });

var model = pipeline.Fit(emptyDv);
return model;

To reproduce

Create an image classification model with 4 channels and try to load the onnx model.

Urgency

Soon

Platform

Windows

OS Version

11

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

2.0.1

ONNX Runtime API

C#

Architecture

X64

Execution Provider

CUDA

Execution Provider Library Version

11.8

@github-actions github-actions bot added ep:CUDA issues related to the CUDA execution provider platform:windows issues related to the Windows platform labels Nov 14, 2023
@gktval
Copy link
Author

gktval commented Nov 14, 2023

Simple mistake, I now see the option for rgba in extract pixels

mlContext.Transforms.ExtractPixels("sequential_input", "image", Microsoft.ML.Transforms.Image.ImagePixelExtractingEstimator.ColorBits.All)

@gktval gktval closed this as completed Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:CUDA issues related to the CUDA execution provider platform:windows issues related to the Windows platform
Projects
None yet
Development

No branches or pull requests

1 participant