I'm trying to debug my tflite model, that uses custom ops. I've found the correspondence between op names (in *.pb) and op ids (in *.tflite), and I'm doing a layer-per-layer comparison (to make sure the outputs difference are always in range 1e-4 (since it blows up at the end, I want to find the exact place where my custom layer fails) as follows:
Method 1: I use get_tensor to get the output as follows:
from tensorflow.contrib.lite.python import interpreter
# load the model
model = interpreter.Interpreter(model_path='model.tflite')
model.allocate_tensors()
# get tensors
for i in tensor_ids:
tensor_output[i] = model.get_tensor(i)
It show totally inadequate random values (comparing to the outputs of the TensorFlow model).
Method 2: convert the *.pb only up to a certain layer, then repeat, basically:
Create a
*.pbso that it contains the network only frominputup tolayer_1.Convert to
tflite(so the output is nowlayer_1) and check the outputs of TF-Lite with TensorFlow.Repeat steps 1-2 for
layer_2,layer_3, ...outputs.
This method requires much more work and executions, but it correctly shows that for built-in operations the outputs of tflite and pb models were identical, and only starts to differ in my custom ops (while in Method 1 the outputs diverges right away from first layers).
Question: Why the behaviour of
get_tensoris so strange? Maybe it is because I am usingtensorflow 1.9(when TF-Lite was still not released and available only in developer preview)?
PS: I am aware about the release of TF-Lite, but I've manually compiled TensorFlow 1.9 for my project and now it is hard to change the versioning.