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)
- TFLiteConverter produces model that doesn't conform to GPUv2 (TfLiteGpuDelegate Init: FULLY_CONNECTED: Amount of input channels should match weights width)
- TextVectorization does not convert Cyrillic characters to lowercase HOT 1
- 2.12.0: memory leak in TFLite's tflite::Interpreter::Invoke() HOT 2
- GPUv2 numerical inaccuracy in simple Add + Mul
- tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. HOT 1
- Aborted (core dumped) with `tf.raw_ops.CombinedNonMaxSuppression` HOT 1
- Aborted (core dumped) with `tf.raw_ops.Dilation2DBackpropFilter`
- Aborted (core dumped) with `tf.raw_ops.FakeQuantWithMinMaxVarsPerChannelGradient` HOT 1
- Segmentation fault (core dumped) in `tf.raw_ops.FractionalMaxPoolGrad` HOT 1
- Aborted (core dumped) with `tf.raw_ops.LRNGrad` HOT 1
- Aborted (core dumped) with `tf.raw_ops.LSTMBlockCell`
- Aborted (core dumped) with `tf.raw_ops.LSTMBlockCellGrad` HOT 1
- Check fail in `tf.raw_ops.MaxPoolGradWithArgmax` HOT 1
- Aborted (core dumped) in `tf.raw_ops.NearestNeighbors`
- Aborted (core dumped) in `tf.raw_ops.SparseBincount`
- Aborted (core dumped) in `TensorScatterOp` HOT 1
- Buffer size mismatch in tensorflow/lite/kernels/stablehlo_pad.cc
- libtensorflow-cpu-windows-x86_64-2.15.0
- Dataset sharding warning
- libhexagon_interface.so for non Android - eLinux platform
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.