小编Dmi*_*rii的帖子

tflite:非输出张量上的 get_tensor 给出随机值

我正在尝试调试我的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到某一层,然后重复,基本上:

  1. 创建一个*.pb,使其仅包含从input到 的网络layer_1

  2. 转换为tflite(因此输出现在为layer_1)并使用 TensorFlow 检查 TF-Lite 的输出。

  3. layer_2对, layer_3, ...重复步骤 1-2 outputs

此方法需要更多的工作和执行,但它正确地表明,对于内置操作,模型的输出tflitepb相同的,并且仅在我的自定义操作中开始有所不同(而在方法 1中,输出立即与第一层不同) 。


问:为什么行为get_tensor …

python keras tensorflow tensorflow-lite

4
推荐指数
1
解决办法
2392
查看次数

标签 统计

keras ×1

python ×1

tensorflow ×1

tensorflow-lite ×1