tensorflow: [TFLite] TfLiteInterpreterInvoke has memory leak and increasing duration time
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
No
Source
source
TensorFlow version
tf 2.15.0
Custom code
Yes
OS platform and distribution
Android/iOS mobile platform
Mobile device
No response
Python version
No response
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
I found memory and duration time increasing when I use tflite C API code in below. The duration time increase 10 msec in just 10 minitues.
TfLiteStatus init(){
// create model
mTFLModel = TfLiteModelCreate(dst_buf, dlc_size);
mTFLInterpreter = TfLiteInterpreterCreate(mTFLModel, NULL);
// Allocate tensor buffers.
mStatus = TfLiteInterpreterAllocateTensors(mTFLInterpreter);
// output buffer
mdnnOutputDataBuffer = new float[OutputSize.width * OutputSize.height];
memset(mdnnOutputDataBuffer, 0, sizeof(float) * OutputSize.width * OutputSize.height );
return mStatus;
}
void release(){
if (mdnnOutputDataBuffer != NULL) delete[] mdnnOutputDataBuffer;
if (mTFLInterpreter != NULL) {
TfLiteInterpreterDelete(mTFLInterpreter);
mTFLInterpreter = NULL;
}
if (mTFLModel != NULL) {
TfLiteModelDelete(mTFLModel);
mTFLModel = NULL;
}
}
TfLiteStatus main(const float* input, uint8_t* intValues) {
TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(mTFLInterpreter,0);
//
mStatus = TfLiteTensorCopyFromBuffer(input_tensor, input, TfLiteTensorByteSize(input_tensor));
//
mStatus = TfLiteInterpreterInvoke(mTFLInterpreter);
const TfLiteTensor* output_tensor =
TfLiteInterpreterGetOutputTensor(mTFLInterpreter, 0);
TfLiteTensorCopyToBuffer(output_tensor, mdnnOutputDataBuffer,
TfLiteTensorByteSize(output_tensor));
}
Now I know is … ・Not depending on tf version(I tried both 2.9.0 and 2.16.1) ・Not depenging on iOS/android(both happen) ・Low resolution input/output model slightly better ・Not depending on device(I tried sevaral devices)
I checked similar mention, but those problem are about NNapi or GPU delegate option. I don’t use delegate option and doesen’t work for me.
- https://github.com/tensorflow/tensorflow/issues/55503
- https://github.com/tensorflow/tflite-support/issues/269
- https://github.com/tensorflow/tensorflow/issues/66736
Standalone code to reproduce the issue
…
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 28 (3 by maintainers)
meet the same problem while using metal delegate with iOS
Hi @kkk-jpeg ,
You can upload your model to your google drive and share a link here or you can mail me at sawantkumar@google.com.