tflite converter crashes with version 2.16.1
@omontf,
By default Tensorflow v2.16 uses keras v3.0 which might be the reason for the error you are facing. As the work-around, Could you please try to install keras 2 where the code was executed without any issue/error. Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/115ecf8fb4b1661329d44d1dc3140d58/untitled1775.ipynb).

```python
!pip install -U tf_keras # Keras 2
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"
```
Thank you! Hi @tilakrayal 

I tried your suggestion.
I confirm that it works well with Keras v2.

Thank you !

Olivier
 @omontf,
Glad the issue is resolved for you, Could you please feel free to move this issue to closed status. Thank you! 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/64273">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/64273">No</a>
 Same issue here. macOS M2.
Above solution is not working for me.


```
2024-04-03 18:55:04.158262: I metal_plugin/src/device/metal_device.cc:1154] Metal device set to: Apple M2
2024-04-03 18:55:04.158289: I metal_plugin/src/device/metal_device.cc:296] systemMemory: 16.00 GB
2024-04-03 18:55:04.158295: I metal_plugin/src/device/metal_device.cc:313] maxCacheSize: 5.33 GB
2024-04-03 18:55:04.158337: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2024-04-03 18:55:04.158350: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1712166904.332563   84530 tf_tfl_flatbuffer_helpers.cc:390] Ignored output_format.
W0000 00:00:1712166904.332624   84530 tf_tfl_flatbuffer_helpers.cc:393] Ignored drop_control_dependency.
2024-04-03 18:55:04.333233: I tensorflow/cc/saved_model/reader.cc:83] Reading SavedModel from: mypath
2024-04-03 18:55:04.334679: I tensorflow/cc/saved_model/reader.cc:51] Reading meta graph with tags { serve }
2024-04-03 18:55:04.334692: I tensorflow/cc/saved_model/reader.cc:146] Reading SavedModel debug info (if present) from: mypath
2024-04-03 18:55:04.352055: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled
2024-04-03 18:55:04.354424: I tensorflow/cc/saved_model/loader.cc:234] Restoring SavedModel bundle.
2024-04-03 18:55:04.420357: I tensorflow/cc/saved_model/loader.cc:218] Running initialization op on SavedModel bundle at path: mypath
2024-04-03 18:55:04.440781: I tensorflow/cc/saved_model/loader.cc:317] SavedModel load for tags { serve }; Status: success: OK. Took 107549 microseconds.
2024-04-03 18:55:04.459571: I tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:268] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.
loc(fused["ReadVariableOp:", "sequential_4_1/conv1d_24_1/Reshape/ReadVariableOp@__inference_serving_default_142497"]): error: missing attribute 'value'
LLVM ERROR: Failed to infer result type(s).
zsh: abort      python3 convert_model.py

``` This issue should be reopened till the problem is really fixed. 
The converter should be updated to work with latest Keras as well. 
Downgrading Keras version(and so losing all the improvements introduced with Keras 3) to prevent crash of Tflite model converter is just a temporary workaround not a proper solution. 
Hello , 

I've got a crash when trying to quantize mnist model with tf 2.16.1 (tested with python 3.10 & 3.11)
Same example works with tf 2.15.0 (python 3.10)

### 1. System information

- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04.5 LTS
- TensorFlow installation (pip package or built from source): pip package
- TensorFlow library (version, if pip package or github SHA, if built from source): 2.16.1 - python 3.11


### 2. Code

Provide code to help us reproduce your issues using one of the following options:
```
import tensorflow as tf
import numpy as np

print("TensorFlow version: ", tf.__version__)

# Load MNIST dataset
mnist = tf.keras.datasets.mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

# Normalize the input image so that each pixel value is between 0 to 1.
train_images = train_images.astype(np.float32) / 255.0
test_images = test_images.astype(np.float32) / 255.0

# Define the model architecture
model = tf.keras.Sequential([
  tf.keras.layers.InputLayer(input_shape=(28, 28)),
  tf.keras.layers.Reshape(target_shape=(28, 28, 1)),
  tf.keras.layers.Conv2D(filters=12, kernel_size=(3, 3), activation='relu'),
  tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(10)
])

# Train the digit classification model
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(
                  from_logits=True),
              metrics=['accuracy'])

model.fit(
  train_images,
  train_labels,
  epochs=1,
  validation_data=(test_images, test_labels)
)

def representative_data_gen():
  for input_value in tf.data.Dataset.from_tensor_slices(train_images).batch(1).take(10):
    yield [input_value]


converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_data_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8

tflite_model_quant = converter.convert()
```
### 3. Error Log

  warnings.warn(
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1711105049.664360 1507500 tf_tfl_flatbuffer_helpers.cc:390] Ignored output_format.
W0000 00:00:1711105049.664404 1507500 tf_tfl_flatbuffer_helpers.cc:393] Ignored drop_control_dependency.
2024-03-22 11:57:29.664698: I tensorflow/cc/saved_model/reader.cc:83] Reading SavedModel from: /tmp/tmpm0lgi7rh
2024-03-22 11:57:29.665327: I tensorflow/cc/saved_model/reader.cc:51] Reading meta graph with tags { serve }
2024-03-22 11:57:29.665351: I tensorflow/cc/saved_model/reader.cc:146] Reading SavedModel debug info (if present) from: /tmp/tmpm0lgi7rh
2024-03-22 11:57:29.671257: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled
2024-03-22 11:57:29.672141: I tensorflow/cc/saved_model/loader.cc:234] Restoring SavedModel bundle.
2024-03-22 11:57:29.694969: I tensorflow/cc/saved_model/loader.cc:218] Running initialization op on SavedModel bundle at path: /tmp/tmpm0lgi7rh
2024-03-22 11:57:29.702319: I tensorflow/cc/saved_model/loader.cc:317] SavedModel load for tags { serve }; Status: success: OK. Took 37624 microseconds.
2024-03-22 11:57:29.712683: I tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:268] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.
loc(fused["ReadVariableOp:", callsite("sequential_1/conv2d_1/Reshape/ReadVariableOp@__inference_serving_default_7052"("/net/minos/minos0/olm_dir/workdir/git/raptor_sdk/tests/model_tests/test/minimal_tf_quant.py":50:1) at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/tensorflow/lite/python/lite.py":1175:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/tensorflow/lite/python/lite.py":1129:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/tensorflow/lite/python/lite.py":1636:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/tensorflow/lite/python/lite.py":1614:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/tensorflow/lite/python/convert_phase.py":205:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/tensorflow/lite/python/lite.py":1537:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/backend/tensorflow/layer.py":58:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/backend/tensorflow/layer.py":120:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py":117:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/layers/layer.py":814:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py":117:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/ops/operation.py":48:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py":156:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/models/sequential.py":202:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/models/functional.py":194:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/ops/function.py":151:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/models/functional.py":578:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py":117:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/layers/layer.py":814:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py":117:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/ops/operation.py":48:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py":156:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/layers/convolutional/base_conv.py":233:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/ops/numpy.py":4507:1 at callsite("/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/backend/tensorflow/numpy.py":1545:1 at "/scorpion/home/olm/.conda/envs/tensorflow_2.16.1/lib/python3.10/site-packages/keras/src/backend/tensorflow/core.py":64:1))))))))))))))))))))))))))]): error: missing attribute 'value'
LLVM ERROR: Failed to infer result type(s).
Aborted (core dumped)

