Comments (5)
@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!
from tensorflow.
@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;
}
from tensorflow.
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!
from tensorflow.
@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.
from tensorflow.
Are you satisfied with the resolution of your issue?
Yes
No
from tensorflow.
Related Issues (20)
- Cannot import tflite_support.task when tensorflow is installed HOT 2
- Incapable of loading a tf v1 model
- Action of the matrix exponential on vectors HOT 2
- Fetch HOT 1
- XNNPACK delegate doesn't support to broadcast last dimension for Prelu operator HOT 1
- Failing Tensorflow unit tests for BF16 hardware
- Interpreter in Swift fails with `EXC_BAD_ACCESS` at `Interpreter.copy(data, toInputAt: 0)` and `Interpreter.input(at: 0)` in some circumstances HOT 1
- Could not find any nvml.h during building from source in docker HOT 1
- Configurable attribute "deps" in @XNNPACK//:prod_microkernels doesn't match this configuration
- benchmark_model no longer cross-compiles for Android from macOS HOT 1
- Inference time using Interpreter API on Android inconsistent and 10–50 times slower than same tflite model on iOS HOT 9
- Basic regression: Predict fuel efficiency Probelm HOT 3
- [
- [Question] Is it possibile to use `jit_compile=True` (XLA) when input is a string? HOT 4
- Homepage sections displaying incorrectly on TensorFlow website HOT 3
- Wrong quantized_dimension (axis) when "per-channel" quantization
- tf.function deadlock with multiple multiprocess/threading HOT 1
- bazel rebuild the file not work HOT 1
- Denial of Service in tf.raw_ops.Unstage HOT 1
- Repository '@python' is not defined HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorflow.