I downloaded a retrained_graph.pb
and retrained_labels.txt
file of a model I trained in Azure cognitive service. Now I want to make an Android app using that model and to do so I have to convert it to TFLite format. I used toco and I am getting the following error:
ValueError: Invalid tensors 'input' were found.
I am basically following this tutorial and have problem on step 4 and direcly copy pasted the terminal code: https://heartbeat.fritz.ai/neural-networks-on-mobile-devices-with-tensorflow-lite-a-tutorial-85b41f53230c
This is a three-step process: Export frozen inference graph for TFLite. Build Tensorflow from source (needed for the third step) Using TOCO to create an optimized TensorFlow Lite Model.
Jul 13, 2022. 1 min read. TensorFlow Lite, often referred to as TFLite, is an open source library developed by Google for deploying machine learning models to edge devices. Examples of edge deployments would be mobile (iOS/Android), embedded, and on-device.
I am making a wild guess here, maybe you entered input_arrays=input
.
Which may not be true. Use this script to find the name of the input and output arrays of the frozen inference graph
import tensorflow as tf
gf = tf.GraphDef()
m_file = open('frozen_inference_graph.pb','rb')
gf.ParseFromString(m_file.read())
with open('somefile.txt', 'a') as the_file:
for n in gf.node:
the_file.write(n.name+'\n')
file = open('somefile.txt','r')
data = file.readlines()
print "output name = "
print data[len(data)-1]
print "Input name = "
file.seek ( 0 )
print file.readline()
In my case they are:
output name: SemanticPredictions
input name: ImageTensor
You can use utility tflite_convert which is the part of tensorflow 1.10 (or higher) package.
The simple use for float inference is something like:
tflite_convert \
--output_file=/tmp/retrained_graph.tflite \
--graph_def_file=/tmp/retrained_graph.pb \
--input_arrays=input \
--output_arrays=output
Where input and output - are input and ouput tensors of your tensorflow graph
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With