Getting wrong output after tflite conversion
@sushreebarsa 
Could you please suggest, what may be the reason for the wrong results? @sushreebarsa 
Is there any update? @priyakansal Sorry for the late response!
The model was saved and loaded successfully with some warnings about untraced functions. Could you consider disabling debug-level logging if it clutters the output. If you're encountering issues after loading the model, please investigate the missing placeholder values (inputs and Placeholder/_0).

Thank you! Hello @sushreebarsa , 
> If you're encountering issues after loading the model, please investigate the missing placeholder values (inputs and Placeholder/_0).

what should I do for the above? @priyakansal Here is  an example;
```
import tensorflow as tf

# Assuming your loaded model is stored in a graph 'model_graph'

# Create a session
sess = tf.Session()

# Prepare your data (replace with your actual data)
input_data = tf.constant([1.0, 2.0, 3.0])  # Example input

# Run the model with placeholders
inference_result, input_value, placeholder_0_value = sess.run(
    [model_graph(inputs=input_data), "inputs:0", "Placeholder/_0:0"]
)

# Check for missing values
if input_value is None:
    print("Missing value for 'inputs' placeholder")
if placeholder_0_value is None:
    print("Missing value for 'Placeholder/_0' placeholder")

sess.close()

```
Please remember to replace the placeholder names and data preparation with your specific model and code.
By using either print statements or the session approach, you can identify if the inputs and Placeholder/_0 placeholders are not receiving the necessary data during inference.

Thank you! 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/63061">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/63061">No</a>

### 1. System information

- OS Platform and Distribution = **Ubuntu 20.04**
- TensorFlow installation (pip package or built from source): **pip installation**
- TensorFlow library (version, if pip package or github SHA, if built from source):**tf-2.12.1**

### 2. Code

Model is converted using the following code:

```
def representative_data_genRGB():
  path = '/content/gdrive/MyDrive/imx_tflite'
  dataset_list = tf.data.Dataset.list_files(path + '/*.jpg')
  for i in range(len(dataset_list)):
    image = next(iter(dataset_list))
    image = tf.io.read_file(image)
    image = tf.io.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, [IMG_HEIGHT, IMG_WIDTH])
    image = tf.cast(image,tf.float32)
    image = image/255.
    image = tf.expand_dims(image, 0)
    yield [image]  

converter = tf.lite.TFLiteConverter.from_saved_model(MODEL_TF)
# converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter. optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_data_genRGB
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.allow_custom_ops = True
converter.inference_type = tf.uint8
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
converter.target_spec.supported_types = [tf.int8]

tflite_model = converter.convert()

with open(MODEL_TFLITE, "wb") as f:
  f.write(tflite_model)

```


### 3. Failure after conversion
If the conversion is successful, but the generated model is wrong, then state what is wrong:
Following Code is used for the prediction:
```
try:
  import tflite_runtime.interpreter as tfl  # prefer tflite_runtime if installed
except ImportError:
  import tensorflow.lite as tfl
MODEL_TFLITE = MODEL_TFLITE
interpreter = tfl.Interpreter(model_path=MODEL_TFLITE)  # load TFLite model
interpreter.allocate_tensors()  # allocate
input_details = interpreter.get_input_details()  # inputs
output_details = interpreter.get_output_details()
img = cv2.imread('20221104084515525.jpg')
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
resized = cv2.resize(img,(IMG_WIDTH,IMG_HEIGHT))/255  
if(len(img.shape) == 3):
    image = np.expand_dims(resized, axis=0)
b,h, w, ch = image.shape  # batch, channel, height, width
inp,out  = input_details[0], output_details[0]
# inp,out1, out2, out3, out4  = input_details[0], output_details[0], output_details[1], output_details[2], output_details[3]
int8 = inp['dtype'] == np.uint8  # is TFLite quantized uint8 model
if int8:
    scale, zero_point = inp['quantization']
    image = (image / scale + zero_point).astype(np.uint8)  # de-scale         
interpreter.set_tensor(inp['index'], image)
interpreter.invoke()
predict = interpreter.get_tensor(out['index'])

if int8:
    if out['quantization'] != (0.0, 0):
        scale, zero_point = out['quantization']
        predict = (predict.astype(np.float32) - zero_point) * scale  # re-scale
```

- **Model produces wrong results:**
The attached images shows the results before and after conversion for the same input image:
Before Conversion/Keras Model Results:
![keras_model_output](https://github.com/tensorflow/tensorflow/assets/38773738/2d4b2abb-4495-4654-9a7f-01671ebee9a9)

After converting into tflite/tflite model results:
![tflite_output](https://github.com/tensorflow/tensorflow/assets/38773738/236754e7-4886-44e1-9b37-a5c0d8553bc1)



### 5. (optional) Any other info / logs
Following are the logs while converting:

```
2024-02-27 17:15:02.854021: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,?,?,?]
	 [[{{node inputs}}]]
2024-02-27 17:15:02.930861: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,?,?,?]
	 [[{{node inputs}}]]
2024-02-27 17:15:03.008753: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,?,?,?]
	 [[{{node inputs}}]]
2024-02-27 17:15:06.708407: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,?,?,?]
	 [[{{node inputs}}]]
2024-02-27 17:15:06.810894: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,?,?,?]
	 [[{{node inputs}}]]
2024-02-27 17:15:06.903451: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,?,?,?]
	 [[{{node inputs}}]]
WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 31). These functions will not be directly callable after loading.
INFO:tensorflow:Assets written to: /home/couger/2nd_shared_dataset/Custom_modelRGBPruned/202422717152_tf2.12-py3.10_96X144-4-channelRGB/model/assets
INFO:tensorflow:Assets written to: /home/couger/2nd_shared_dataset/Custom_modelRGBPruned/202422717152_tf2.12-py3.10_96X144-4-channelRGB/model/assets
2024-02-27 17:15:11.449645: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:364] Ignored output_format.
2024-02-27 17:15:11.449671: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:367] Ignored drop_control_dependency.
2024-02-27 17:15:11.449833: I tensorflow/cc/saved_model/reader.cc:45] Reading SavedModel from: /home/couger/2nd_shared_dataset/Custom_modelRGBPruned/202422717152_tf2.12-py3.10_96X144-4-channelRGB/model
2024-02-27 17:15:11.461083: I tensorflow/cc/saved_model/reader.cc:89] Reading meta graph with tags { serve }
2024-02-27 17:15:11.461098: I tensorflow/cc/saved_model/reader.cc:130] Reading SavedModel debug info (if present) from: /home/couger/2nd_shared_dataset/Custom_modelRGBPruned/202422717152_tf2.12-py3.10_96X144-4-channelRGB/model
2024-02-27 17:15:11.496457: I tensorflow/cc/saved_model/loader.cc:231] Restoring SavedModel bundle.
2024-02-27 17:15:11.679895: I tensorflow/cc/saved_model/loader.cc:215] Running initialization op on SavedModel bundle at path: /home/couger/2nd_shared_dataset/Custom_modelRGBPruned/202422717152_tf2.12-py3.10_96X144-4-channelRGB/model
2024-02-27 17:15:11.754645: I tensorflow/cc/saved_model/loader.cc:314] SavedModel load for tags { serve }; Status: success: OK. Took 304813 microseconds.
2024-02-27 17:15:12.143006: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'Placeholder/_0' with dtype string and shape [43]
	 [[{{node Placeholder/_0}}]]
2024-02-27 17:15:12.143348: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'Placeholder/_0' with dtype string and shape [43]
	 [[{{node Placeholder/_0}}]]
fully_quantize: 0, inference_type: 6, input_inference_type: UINT8, output_inference_type: UINT8
/home/couger/2nd_shared_dataset/Custom_modelRGBPruned/202422717152_tf2.12-py3.10_96X144-4-channelRGB/model.tflite

```

