Input shape is not compatible

Hello. I’m trying to run a very basic model that just applies 2x-1 rule to a number.
The model itself has one Dense layer (Dense(units=1, input_shape=[1])) and when called using Keras API directly (model.predict([10.0])) works perfectly.
However when I’ve imported the model as onnx into Unity and ran simple test I’ve got a warning:

Given input shape: (1) is not compatible with model input shape: (unk__11, 1) for input: dense_input

I’m feeding input like this:

float data = new float { 10f };
TensorShape shape = new TensorShape(1);
TensorFloat tensor = new TensorFloat(shape, data);

Debug.Log(“EXECUTE”);

worker = WorkerFactory.CreateWorker(BackendType.GPUCompute, runtimeModel, verbose: true);
worker.Execute(tensor);

Debug.Log(“RESULT”);

TensorFloat outputTensor = worker.PeekOutput() as TensorFloat;

Also tried to feed input just like new TensorFloat(10f) - no result.
I’m wondering what am I missing in conversion from an input number to (unk__11, 1) format.

(unk__11, 1) is the shape of the tensor, it’s a rank 2 tensor with first dimension variable, the second dimension is 1.

That means only input vectors of the form (x, 1) can be passed here. E.g. (0, 1), (1, 1), (2, 1) etc. would all be valid input tensors. In your case it sounds like you need TesnorShape(1, 1). The unknown dimension is probably something that got added in the conversion step to onnx format.

1 Like

Indeed. After changing tensorShape to new TensorShape(1, 1) model returned valid result.
Thank You very much for clarification @gilescoope

1 Like