Title: Finding Input and output tensors from .pb file
Tags: python-3.x;tensorflow;computer-vision;tensorflow-lite
Question: I created a .pb model thanks to roboflow.ai and I'm now trying to convert the .pb file into .tflite so I can use it in an Android app I'm hoping to develop. I'm struggling to do the conversion because I have to put in my 'input' and 'output' tensors.
I found a script that gave me my input tensor as 'image_tensor' but it gives me my output tensors as:
'Postprocessor/BatchMultiClassNonMaxSuppression/map/while/Switch',
'raw_detection_boxes',
'MultipleGridAnchorGenerator/assert_equal_1/Assert/Assert',
'detection_boxes',
'detection_scores',
'Postprocessor/BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/SortByField/TopKV2',
'detection_multiclass_scores',
'Postprocessor/BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/SortByField/Assert/Assert',
'Postprocessor/BatchMultiClassNonMaxSuppression/map/while/Switch_1',
'Postprocessor/BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/SortByField_1/Assert/Assert',
'detection_classes',
'num_detections',
'Postprocessor/BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/SortByField_1/TopKV2',
'Preprocessor/map/while/Switch_1',
'Preprocessor/map/while/Switch',
'raw_detection_scores'
I've tried all of this and different combinations of this but I'm unsure what I should be using (or if it even is the correct thing).
I'm trying to put this into the following code:
import tensorflow as tf
localpb = 'retrained_graph_eyes1za.pb'
tflite_file = 'retrained_graph_eyes1za.lite'
print("{} -&gt; {}".format(localpb, tflite_file))
converter = tf.lite.TFLiteConverter.from_frozen_graph(
localpb,
['input'],
['final_result']
tflite_model = converter.convert()
open(tflite_file,'wb').write(tflite_model)
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()
I'm using TensorFlow v1x as this is what roboflow.ai recommends.
Any help?
Comment: Thanks for this, I found my input and output tensors eventually but then encountered another error. In the end I switched to a different tutorial and was able to train my .tflite model which works with teh Tesorflow Android Studio example.. I'm still using Tensorflow 1x. I'd love to find a good end to end example on Tensorflow 2, preferably using Yolo V5. As an Android developer, I've spent ages on this when all I want is my model on a mobile phone.

Comment: Transforming .pb to .tflite is a pain sometimes. Specially at versions Tensorflow v.1 ... You have to check operators compatibility [here](https://www.tensorflow.org/lite/guide/ops_compatibility)  before you try it. I would recommend train the model again with tensorflow version 2. It is easier the transformation



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:06/14/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python-3.x><tensorflow><computer-vision><tensorflow-lite>', 'Title': 'Finding Input and output tensors from .pb file', 'ViewCount': 410, 'id': 62372149, 'user_AboutMe': '', 'user_AccountId': 3979347.0, 'user_DisplayName': 'MarkC', 'user_Reputation': 49.0, 'user_Views': 14.0, 'user_id': 3281703.0}}