We have a problem when converting a pretrained Tensorflow model which we took as following files
snapshot_140.ckpt.index
snapshot_140.ckpt.meta
snapshot_140.ckpt.data-00000-of-00001
to tensorflow lite when we used the converted tflie file to make predictions , all predictions where Nan while the normal tensorflow model when loaded gave correct regression prediction
we got these files above, conversion from ckpt files to tensorflow .pb graph takes place via tensorflow.python.tools.freeze_graph tool
then TFlite_converter tool for converting to tflite
.pb works well when made into a tensorflow model.. but tflite model produces all nan output
one (potential solution) is inspired from this issue: https://github.com/tensorflow/tensorflow/issues/22803?fbclid=IwAR0x25CEZjHAQ0dUFBVWa1V3lVcCVIpT4q7lbUUGS9T59w2aXqnUVtNCBHI#issuecomment-474249701
so how to set batch_norm is_training flag to false given only ckpt files with no access to model architecture ?
if this is really the solution to the problem
or what should we do to fix the tensorflow lite model to give the same outputs as the tensorflow model
this code was used to get the tensorflow lite model which gave nans
import tensorflow as tf
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True,
log_device_placement=True)) as sess:
saver = tf.train.import_meta_graph('snapshot_140.ckpt.meta')
saver.restore(sess, "snapshot_140.ckpt")
inp = tf.get_default_graph().get_tensor_by_name("tower_0/Placeholder:0")
out = tf.get_default_graph().get_tensor_by_name("tower_0/out/BiasAdd:0")
print(out)
converter = tf.contrib.lite.TFLiteConverter.from_session(sess, [inp], [out])
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)