Unexpected input dimension (tflite C_API library)
@saad-koukous,
Could you please share colab link or simple standalone code with supporting files to reproduce the issue in our environment. It helps us in localizing and debugging the issue faster. Thank you! @tilakrayal,
Thank you for your response. However, I can't share the .tflite model and data. As I mentioned before, the expected input dimensions are 1x3x40x180. When I use the model in Python, I provide input with these dimensions. But when using the C API, it indicates that the dimensions are 1x3x1x1. Below is a snippet of my C code.
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tensorflow/lite/c/c_api.h>
int main() {
    // Load the TFLite model
    const char* model_path = "model.tflite";
    TfLiteModel* model = TfLiteModelCreateFromFile(model_path);
    if (!model) {
        printf("Failed to load the model.\n");
        return 1;
    }
    // Create an interpreter
    TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
    TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
    TfLiteInterpreterOptionsDelete(options);
    if (!interpreter) {
        printf("Failed to create the interpreter.\n");
        return 1;
    }
    // Allocate input tensors
    TfLiteInterpreterAllocateTensors(interpreter);
    // Get the input tensor
    TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 0);
    int num_dims = TfLiteTensorNumDims(input_tensor);
    int dim1 = TfLiteTensorDim(input_tensor, 0);
    int dim2 = TfLiteTensorDim(input_tensor, 1);
    int dim3 = TfLiteTensorDim(input_tensor, 2);
    int dim4 = TfLiteTensorDim(input_tensor, 4);
    printf("Input tensor:\n");
    printf("Number of dimensions: %i\n", num_dims);
    printf("Dimensions: %i x %i x %i x %i\n", dim1, dim2, dim3, dim4);
    if (TfLiteTensorType(input_tensor) != kTfLiteFloat32) {
    printf("Unexpected data type in the input tensor.\n");
    return 1;
}

    // Set the input data

    // the input data is a 3D array of shape (3, 40, 180)

    // Allocate memory for the input data

    printf("stacked_input_data[0]: %f\n", stacked_input_data[0]);

    TfLiteStatus copy_status = TfLiteTensorCopyFromBuffer(input_tensor, stacked_input_data,3 * 40 * 180 * sizeof(float) );

    if (copy_status != kTfLiteOk) {

    printf("Failed to copy input data to tensor.\n");

    return 1;

    }

    printf("data copied\n");

    if (interpreter == NULL) {

        printf("Interpreter is null.\n");

        return 1;

    }
    // Free the memory for the stacked input data

    free(stacked_input_data);

    TfLiteStatus invoke_status = TfLiteInterpreterInvoke(interpreter);

    if (invoke_status != kTfLiteOk) {

        printf("Failed to invoke interpreter.\n");

        return 1;

    }
    // Get the output tensor

    const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0);

    // Process the output data as needed

    // Assuming the output is a float array called 'output_data'

    float* output_data = (float*)malloc(40 * 180 * sizeof(float));

    if (!output_data) {
        printf("Failed to allocate memory for the output data.\n");
        free(output_data);
        return 1;
    }
    TfLiteTensorCopyToBuffer(output_tensor, output_data,40 * 180 * sizeof(float));
    // Clean up
    free(output_data);
    TfLiteInterpreterDelete(interpreter);
    TfLiteModelDelete(model);
    return 0;
}
``` Hi @saad-koukous, can you please show us a colab/code for how the model is produced in Python? usually you see this when those dimensions are dynamic in Python but were not explicitly set in some way but C++ doesn't have the right information to infer the actual dimensions. Explicitly setting the dimensions in Python or Resizing them in C++: https://www.tensorflow.org/lite/guide/inference#run_inference_with_dynamic_shape_model will likely resolve your issue. Let us know if that works. Thanks! @pkgoogle  Thank you so much! I discovered that the model's input has dynamic dimensions, so I regenerated a TFLite model with fixed input dimensions. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/65515">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/65515">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

2.17.0

### Custom code

Yes

### OS platform and distribution

Ubuntu 22.04.4 LTS

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

bazel 6.5.0

### GCC/compiler version

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I expect an input tensor dimension of 1 x 3 x 40 x 180, but when running found dimension 1x3x1x1
```
int num_dims = TfLiteTensorNumDims(input_tensor);
int dim1 = TfLiteTensorDim(input_tensor, 0);
int dim2 = TfLiteTensorDim(input_tensor, 1);
int dim3 = TfLiteTensorDim(input_tensor, 2);
int dim4 = TfLiteTensorDim(input_tensor, 4);
```
I need help to understand the problem, and i need clarification to how to use `TfLiteTensorCopyFromBuffer` for my dimension case

### Standalone code to reproduce the issue

```shell
...
TfLiteStatus copy_status = TfLiteTensorCopyFromBuffer(input_tensor, stacked_input_data,3 * 40 * 180 * sizeof(float) );
    if (copy_status != kTfLiteOk) {
    printf("Failed to copy input data to tensor.\n");
    return 1;
    }
```


### Relevant log output

```shell
Input tensor:
Number of dimensions: 4
Dimensions: 1 x 3 x 1 x 1
input_data[0]: 0.937447
Failed to copy input data to tensor
```
