【发布时间】:2019-04-06 04:35:57
【问题描述】:
我正在尝试调试我的 tflite 模型,它使用自定义操作。我找到了操作名称(*.pb)和操作 ID(*.tflite)之间的对应关系,并且我正在进行逐层比较(以确保输出差异始终在@987654324 范围内@(因为最后炸了,我想找到我的自定义层失败的确切位置)如下:
方法一:我使用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)
它显示完全不充分的随机值(与 TensorFlow 模型的输出相比)。
方法2:将*.pb只转换到某一层,然后重复,基本上:
创建一个
*.pb,使其仅包含从input到layer_1的网络。转换为
tflite(因此输出现在为layer_1)并使用TensorFlow检查TF-Lite的输出。对
layer_2、layer_3、...outputs重复步骤 1-2。
这种方法需要更多的工作和执行,但它正确地表明,对于内置操作,tflite 和 pb 模型的输出是相同的,只是在我的自定义操作中开始有所不同(而在 方法 1 输出立即从第一层发散)。
问题:为什么
get_tensor的行为如此奇怪?可能是因为我用的是tensorflow 1.9(当时TF-Lite还没有发布,只在开发者预览版中可用)?
PS:我知道 TF-Lite 的发布,但我已经为我的项目手动编译了 TensorFlow 1.9,现在很难更改版本。
【问题讨论】:
标签: python tensorflow keras tensorflow-lite