Skip to content Skip to sidebar Skip to footer

Obtain Input_array And Output_array Items To Convert Model To Tflite Format

PS. Please dont point me to converting Keras model directly to tflite as my .h5 file would fail to convert to .tflite directly. I somehow managed to convert my .h5 file to .pb I ha

Solution 1:

input arrays and output arrays are the arrays which store input and output tensors respectively.

They intend to inform the TFLiteConverter about the input and output tensors which will be used at the time of inference.

For a Keras model,

The input tensor is the placeholder tensor of the first layer.

input_tensor = model.layers[0].input

The output tensor may relate with a activation function.

output_tensor = model.layers[ LAST_LAYER_INDEX ].output

For a Frozen Graph,

import tensorflow as tf
gf = tf.GraphDef()   
m_file = open('model.pb','rb')
gf.ParseFromString(m_file.read())

We get the names of the nodes,

for n in gf.node:
    print( n.name )

To get the tensor,

tensor = n.op

The input tensor may be a placeholder tensor. Output tensor is the tensor which you run using session.run()

For conversion, we get,

input_array =[ input_tensor ]
output_array = [ output_tensor ]

Post a Comment for "Obtain Input_array And Output_array Items To Convert Model To Tflite Format"