我正在尝试调试我的tflite模型,该模型使用自定义操作。我找到了操作名称(in *.pb)和操作ID(in *.tflite)之间的对应关系,并且我正在进行逐层比较(以确保输出差异始终在范围内1e-4(因为它在最后爆炸) ,我想找到我的自定义层失败的确切位置)如下:
方法1:我使用get_tensor如下方式获取输出:
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)
Run Code Online (Sandbox Code Playgroud)
它显示的随机值完全不足(与 TensorFlow 模型的输出相比)。
方法2:只转换*.pb到某一层,然后重复,基本上:
创建一个*.pb,使其仅包含从input到 的网络layer_1。
转换为tflite(因此输出现在为layer_1)并使用 TensorFlow 检查 TF-Lite 的输出。
layer_2对, layer_3, ...重复步骤 1-2 outputs。
此方法需要更多的工作和执行,但它正确地表明,对于内置操作,模型的输出tflite是pb相同的,并且仅在我的自定义操作中开始有所不同(而在方法 1中,输出立即与第一层不同) 。
问:为什么行为
get_tensor …