Yolov8 tflite python output is not matching with tflite cpp output for float32 models
Hi @ajithkumarmcw 

Python binding actually uses the C++ implementation of Tensorflow Lite. Considering the Python runtime overhead itself, It is expected, under the same running environment, the Python performance should be no better than that of the C++ one.

Btw, you could use the [TFLite benchmark tool](https://www.tensorflow.org/lite/performance/measurement) to measure the performance of your model.  

Also, can you test the same in latest 2.12 version?


Thanks. @pjpratik my issue is not with performance its with the output which i am getting 

This is the code and model files i am using https://github.com/ajithkumarmcw/Yolo_tflite_detection , i am not getting any error but the predictions are almost wrong.
In python the tflite model files are working fine
Below are the cpp inference outputs for the tflite models generated from yolov5n.pt/yolov8n.pt files which i took from Yolov5 and Yolov8 repo repectively

Environment: tensorflow==2.4.2, Ubuntu==20.04,bazel==3.7.2, gcc==9.4.0

- case1: For Yolov5 int 8 tflite model i am getting below output its fine
<img width="490" alt="snap_yolov5_int8" src="https://user-images.githubusercontent.com/84714146/235165051-64510b5b-3c6b-4d61-891a-9ae9d8430e6a.png">

- case2: For Yolov5 float 16 tflite model i am getting below output and its predictions, labels, bboxes are wrong
<img width="494" alt="snap_yolov5_float16" src="https://user-images.githubusercontent.com/84714146/235165249-1476151d-c96c-4468-8059-47e0c6b3cdc6.png">


- case3: For Yolov8 int8 tflite model i am getting below output and its predictions, labels, bboxes are wrong

<img width="488" alt="snap_yolov8_int8" src="https://user-images.githubusercontent.com/84714146/235165341-dd5d2d68-2b0e-470c-9d04-de2a7a99c51e.png">

- case4: For Yolov8 float 32 tflite model i am getting below output and its predictions, labels, bboxes are wrong

<img width="488" alt="snap_yolov8_float32" src="https://user-images.githubusercontent.com/84714146/235165381-c658b5e9-3608-4c68-9b72-d0c461a860d1.png">

I am not sure why the predictions are correct for Yolov5 uint8 but its failing for other three cases Hi @ajithkumarmcw, can you provide the video file that produced the above results? I was able to compile on the latest TF code by d/ling your code and modifying where the TF source directory was coming from but it's now asking me for an input video and output video file, would you mind sharing the input video which produced the above frames? A very short video w/ just the offending frame would be preferred or any other format that is more easily shareable (and short/small):

```
ls
abseil-cpp      CMakeFiles             debug.sh  fft2d              FP16-download   FXdiv-source  ml_dtypes       psimd-source          release.sh       tmp
buildtests.sh   cmake_install.cmake    _deps     flatbuffers        FP16-source     gemmlowp      neon2sse        pthreadpool           ruy              xnnpack
check.sh        compile_commands.json  eigen     flatbuffers-flatc  FXdiv           main          psimd           pthreadpool-download  src
CMakeCache.txt  cpuinfo                farmhash  FP16               FXdiv-download  Makefile      psimd-download  pthreadpool-source    tensorflow-lite
(base) xxxxxxx@pklinuxmaster:~/git/Yolo_tflite_detection/build$ ./main

Error! Usage: <path to tflite model> <path to classes names> <path to input video> <path to output video>
```

also what is the "path to classes names" referring to.. is that a text file which you have?

Thanks for your help. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. 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/60415">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/60415">No</a>
 Hi, @ajithkumarmcw ,

can i check if you were able to solve this issue? I am doing a similar project and experiencing the same problem. Do you mind sharing with me your code? @Thunderzen  the problem was in the tflite inference code . i was not reshaping the image, was not preprocessing as per yolov8, and i was using the same script for both yolov5 and v8 so the the bounding boxes were not correct i forgot exact reason but it was like this . U can check this code https://github.com/ajithkumarmcw/Yolo_tflite_detection/tree/main/src or any tflite yolov8 code in github. And the output of yolov5 and yolov8 models are different so you can check for some inference script specifically written for yolov8 Hi @ajithkumarmcw, do you have the code for yolov8 instead? I am having troubles with the post-processing of the outputs? Also, I can't seem to find implementations by others on github. Most seemed to be for the Python version and I have completed the Python code but the c++ implementation is quite different. Thanks! Sorry i did it for my office so i cant share it but you can check below
https://github.com/JustasBart/yolov8_CPP_Inference_OpenCV_ONNX
https://github.com/Li-99/yolov8_onnxruntime
https://github.com/ultralytics/ultralytics/tree/main/examples/YOLOv8-ONNXRuntime-CPP
https://github.com/yide1235/YOLOv8-Inference-TFLite-Openvino/tree/main

if above didnt help and if u can share u r code. u can share to inocajith21.5@gmail.com i will look in to it. if u r using onnx model script first check what is the difference between the output of onnx model output and tflite model output for the same input (u can give a random numpy array). u can then modify the onnx model script to work for tflite.
### 1. System information

- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
- TensorFlow installation (pip package or built from source):  built from source
- TensorFlow library (version, if pip package or github SHA, if built from source): tensorflow==2.4.2

### 2. Code

Provide code to help us reproduce your issues using one of the following options:

Used following three files 
https://github.com/muhammedakyuzlu/yolov5-tflite-cpp/blob/main/src/main.cpp
https://github.com/craft-zhang/tensorflow-lite-cpp-examples/blob/main/yolov5.cc
https://github.com/craft-zhang/tensorflow-lite-cpp-examples/blob/main/yolov5.h



### 3. Failure after conversion
If the conversion is successful, but the generated model is wrong, then state what is wrong:

- Model produces wrong results and/or has lesser accuracy.
- I am using Yolov8 model, In python tflite model is predicting correctly but same model when we use it in cpp with above script its not able to give same outputtensor as like python's output
because of this problem models output scores, labels are going to 10000, 20000 like that. Kindly help us to sort this issue

