tensorflow / tensorflow/models
The order of object detection output tensors in TF2 TFLITE model is different from TF1 and from description in export_tflite_graph_tf2.py
@laxmareddyp is already working on this.
Since Apr 1, 2023.
- Dominant language
- Python
- Stars
- 77.7k
- Forks
- 44.8k
- PR merge metrics
- No merged PRs in 30d
Description
Prerequisites
Please answer the following questions for yourself before submitting an issue.
[+] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
[+] I am reporting the issue to the correct repository. (Model Garden official or research directory)
[+] I checked to make sure that this issue has not already been filed.
1. The entire URL of the file you are using
2. Describe the bug
According to the comments in export_tflite_graph_tf2.py, it should generate 4 output tensors in the following order:
detection_boxes: a float32 tensor of shape [1, num_boxes, 4] with box locations
detection_classes: a float32 tensor of shape [1, num_boxes] with class indices
detection_scores: a float32 tensor of shape [1, num_boxes] with class scores
num_boxes: a float32 tensor of size 1 containing the number of detected boxes
This was, in fact, the order of outputs produced by export_tflite_ssd_graph.py in TF1.
However, export_tflite_graph_tf2.py, followed by execution of tflite_convert.py in TF2, produces output tensors in this order:
detection_scores
detection_boxes
num_boxes
detection_classes
Which creates incompatibility between TF1 and TF2 for run-time inferencing at the edge.
3. Steps to reproduce
*) Train an object detection model (I am using ssd_mobilenet_v2_128x128_coco17_tpu-8)
*) Export TF2 TFLITE saved_model:
python object_detection/export_tflite_graph_tf2.py --pipeline_config_path=${CONFIG_FILE} --trained_checkpoint_dir=${MODEL_DIR} --output_directory=${OUTPUT_DIR}
*) Convert to TFLITE format:
python tflite_convert.py --output_file=${TFLITE_FILE} --saved_model_dir=${TFLITE_SAVED_MODEL_DIR}
*) Run inference in Python and examine interpreter's output details:
output_details = interpreter.get_output_details()
4. Expected behavior
Expected order of output tensors should be as described in export_tflite_graph_tf2.py, which should be identical to the order of output tensors produced in TF1 TFLITE.
5. Additional context
N/A
6. System information
- TensorFlow 2.10.0
- Python version 3.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.