Error during execution

Im trying to run a simple object detection model (converted from tflite to onnx) and i get these errors:

Given input shape: (1, 3, 1024, 2048) has different dimension from model input shape: (1, 320, 320, 3) for input: serving_default_images at axis: 1

AssertionException: TensorShape.ValueError: operands could not be broadcast together with shapes (1, 64, 1, 16), (1, 64, 1, 13)

I use the example code from the docs, any ideas?

Hi,

Thank you for reporting this issue!

Can you share the model? You can also make a bug report by following these steps if you think this is a bug.

Error message says it all:
https://docs.unity3d.com/Packages/com.unity.sentis@1.0/manual/models-concept.html
https://docs.unity3d.com/Packages/com.unity.sentis@1.0/manual/create-an-input-tensor.html
Your model is saved with a input shape of (1, 3, 320, 320) but you are running it with (1, 3, 1024, 2048)
Therefor you might encounter run-time problem as we might have baked things in your imported model with the assumption that the input shape is always 1,3,320,320 :slight_smile:
The solution is to make the input shape dynamic shapes in the onnx model

Thanks @alexandreribard_unity @liutaurasvysniauskas_unity i guess i will just reshape the images to 320x320 and try again cause i dont know how to do the other think u suggested. Im following this tutorial:

and used this to convert it:

just FYI, you can do that easily with the TextureConverter new TextureTransform().SetDimensions(1, 1, 4)

Thank u, could you give me a usage example? Im currently doing this:

    void Start()
    {
        // Create the runtime model
        runtimeModel = ModelLoader.Load(modelAsset);

        // Create input data as a tensor
        Tensor inputTensor = TextureConverter.ToTensor(inputTexture);

        // Create an engine
        worker = WorkerFactory.CreateWorker(BackendType.GPUCompute, runtimeModel);

        // Run the model with the input data
        worker.Execute(inputTensor);

        // Get the result
        TensorFloat outputTensor = worker.PeekOutput() as TensorFloat;
        results = outputTensor.ToReadOnlyArray();
    }
 Tensor inputTensor = TextureConverter.ToTensor(inputTexture, width: 320, height: 320);
1 Like

AssertionException: ValueError: reshaped length does not match with input length

Given input shape: (1, 3, 320, 320) has different dimension from model input shape: (1, 320, 320, 3) for input: serving_default_images at axis: 3

It seems i need to switch places between the 3 and the 320 somehow, any ideas?

Oh missed that, your model is NHWC and not NCHW
Tensor inputTensor = TextureConverter.ToTensor(inputTexture, new TextureTransform().SetDimensions(width: 320, height: 320).SetTensorLayout(TensorLayout.NHWC)

Ok it worked but i the results im getting floats, shouldnt i get the labels of the detected objects? Also i get these:

Looking at your code you are not disposing the input tensor that you’ve allocated.
Also the labels, it depends on your model. Typically the model gives you a probability per class.
You then need to take the softmax/argmax and map that to your string labels
You can follow the ExecuteOperatorOnTensor sample

How do I dispose it? Sorry im new to all this

either you do inputTensor.Dispose() or using inputTensor = ....

Ok so i get around 19k floats which could be a label each cause its a large model. But i should also be getting back bounding boxes too cause how do i know where it was detected?

Isn’t mobilenet outputting label probability only? Checking the tutorial I’m assuming you get a 1,1000 output. which you apply softmax and argmax. you then sample the dictionary labels.json to get the label.
If your model works with bounding box then my guess is you get some tensor of 1,1000,4 and in this case it’s the uv coord for the bounding box per class.
I’d check the shape of the output tensor and check the tutorial on what is the output supposed to mean

TensorFloat(1, 19206, 90) this is the tensor i get which doesnt make much sense. 19k for labels are too many and no clue what 90 is. but the same model used in js outputs label, probability and bounding boxes so the data do exists in it