Centernet TFLite for multiple keypoint tasks crashes, but only on specific images
@biantsh Thanks for reporting this issue.

I was able to reproduce this issue on TF 2.13 and TF Nightly 2.15.0-dev20230824. Please find the gist of 2.13 [here](https://colab.research.google.com/gist/pjpratik/ecb71c98424c0e3ed6f67fadbcd38638/59833.ipynb) and nightly [here](https://colab.research.google.com/gist/pjpratik/b0214fce68068616621016f371b27f00/59833.ipynb).

@sachinprasadhs Could you please look into this? Thanks. Hi @biantsh 

The link to the models seems to be broken. Could you please provide the access to the models and data if possible?

Thanks. 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. Hey @pjpratik, apologies for the oversight.

I've updated the links and they should be working now. 

Thank you!
### 1. System information

- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04):**

  Linux Ubuntu 20.04

- **TensorFlow installation (pip package or built from source):**

  Pip package

- **TensorFlow library (version, if pip package or github SHA, if built from source):**

  2.11.0

### 2. Code

Drive link to the model, including checkpoints, SavedModel and TFLite model: https://drive.google.com/drive/folders/1E0Ris0mfS4s5iWsLcqIoDK03dQO7nJ7T?usp=sharing
Drive link to a working image and a non-working (crashing) image: https://drive.google.com/drive/folders/1U0F-j8ZYYABRtbXm8hyWexP3gna5_ln9?usp=sharing

To convert the model, I first ran the `export_tflite_graph_tf2.py` script ([GitHub link](https://github.com/tensorflow/models/blob/master/research/object_detection/export_tflite_graph_tf2.py)) with the following command:

```
python3 export_tflite_graph_tf2.py  \
  --pipeline_config_path pipeline.config  \
  --trained_checkpoint_dir checkpoint/  \
  --output_directory .  \
  --keypoint_label_map_path label_map.pbtxt
  --centernet_include_keypoints true
```

Then, I converted the generated `saved_model` to TFLite using the `tflite_convert.py` script ([GitHub link](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/python/tflite_convert.py)) with the following command:

```
tflite_convert --saved_model_dir saved_model --output_file model.tflite
```

This successfully generates a `model.tflite` file. To run it, I'm using the following reference code (replacing the `model_path` and `image_path` variables with the correct paths):

```
import cv2 as cv
import numpy as np
import tensorflow as tf

model_path = '---'
image_path = '---'

interpreter = tf.lite.Interpreter(model_path)
interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
input_shape = input_details[0]['shape']
input_dtype = input_details[0]['dtype']
input_index = input_details[0]['index']

# Load and preprocess image
image = cv.imread(image_path)
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
image = cv.resize(image, input_shape[2:0:-1])
image = np.expand_dims(image, 0)
image = image.astype(input_dtype)

# Inference
interpreter.set_tensor(input_index, image)
interpreter.invoke()
```

### 3. Failure after conversion

Running the code with the image named `working.jpg` produces the following logs, indicating that there is no error:

```
2023-02-28 11:23:15.406260: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-02-28 11:23:16.388488: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/biant/anaconda3/envs/test/lib/python3.10/site-packages/cv2/../../lib64::/home/biant/anaconda3/envs/solabml/lib/:/home/biant/anaconda3/envs/test/lib/
2023-02-28 11:23:16.388599: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/biant/anaconda3/envs/test/lib/python3.10/site-packages/cv2/../../lib64::/home/biant/anaconda3/envs/solabml/lib/:/home/biant/anaconda3/envs/test/lib/
2023-02-28 11:23:16.388615: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
```

Running the code with the image named `not_working.jpg` produces the following logs and error:

```
2023-02-28 11:24:18.121298: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-02-28 11:24:19.110612: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/biant/anaconda3/envs/test/lib/python3.10/site-packages/cv2/../../lib64::/home/biant/anaconda3/envs/solabml/lib/:/home/biant/anaconda3/envs/test/lib/
2023-02-28 11:24:19.110720: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/biant/anaconda3/envs/test/lib/python3.10/site-packages/cv2/../../lib64::/home/biant/anaconda3/envs/solabml/lib/:/home/biant/anaconda3/envs/test/lib/
2023-02-28 11:24:19.110735: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
  File "/home/biant/inference.py", line 25, in <module>
    interpreter.invoke()
  File "/home/biant/anaconda3/envs/test/lib/python3.10/site-packages/tensorflow/lite/python/interpreter.py", line 917, in invoke
    self._interpreter.Invoke()
RuntimeError: tensorflow/lite/kernels/unpack.cc:43 NumElements(input) > 0 was not true.Node number 297 (UNPACK) failed to prepare.
```

### 5. (optional) Any other info / logs

1. There isn't anything special about these two example images, they are from the validation set of Coco-2017 (the training set was used for training the model). The same results can be achieved by trying other random images.

2. On the working image, the detections can be printed and visualized, and the keypoints for both the 'person' and 'face' categories are detected correctly. This suggests that the TFLite model isn't *incapable* of predicting keypoints for two different categories.

3. Converting the checkpoints to a SavedModel using the script `exporter_main_v2.py` ([GitHub link](https://github.com/tensorflow/models/blob/master/research/object_detection/exporter_main_v2.py)) results in a model that doesn't crash with any images. This indicates that the issue is only related to the TFLite model.
3.1 - When observing the images that *don't* crash the TFLite model, it seems like in all cases at least one category 'person' and one category 'face' is predicted (out of the 10 detections that the model outputs).
3.2 - On the images that *do* crash the TFLite model, running them through the SavedModel version reveals that in almost all cases the detections consist of either all 'persons' or all 'faces'. Is it possible that the TFLite model crashes when it only predicts one of the categories?
3.3 - There were a few exceptions to point 3.2, but they were rare enough that the exceptions might just be due to the slight differences between the SavedModel and TFLite model.

**Edit:** As expected, increasing `--max_detections` during model conversion reduces the likelihood that the model will crash. For example, after increasing the number of detections from 10 to 100, only ~5% of the previously offending images are still causing a crash. Could this be due to the fact that when there are more detections outputted, the chance that both classes are detected increases?