【问题标题】:Cannot load tflite model, Did not get operators or tensors in subgraph 1无法加载 tflite 模型,在子图 1 中未获取运算符或张量
【发布时间】:2021-09-06 04:56:15
【问题描述】:

我已将 tf 模型转换为 tflite,并在此过程中应用了量化,但我无法加载它。当我尝试执行interpreter = tf.lite.Interpreter(tflite_model_path) 时出现错误,错误消息是:

ValueError: Did not get operators or tensors in subgraph 1.

同样在量化过程中,我的模型中的每个密集层都收到了很多这样的 INFO 消息:

2021-09-06 04:38:40.879693: I tensorflow/lite/tools/optimize/quantize_weights.cc:217] Skipping quantization of tensor bert_token_clssfification/classifier/Tensordot/Shape that is not type float.

这些消息让我非常困惑,因为我确信这些权重是 float32 类型的。任何想法我做错了什么?谢谢!

【问题讨论】:

    标签: tensorflow tensorflow-lite quantization


    【解决方案1】:

    我找出了我的情况的原因。这是因为我的模型中有 dropout 层,并且我使用输入 tf.bool 张量来显式控制 dropouts 层的训练/推理模式。 tflite 目前不支持 dropout,因为我明确控制 dropout 行为,tflite 转换无法删除 dropout 操作。

    使用 dropout 的正确方法是在模型调用期间传递 training kwarg:out = model(input_batch, training=True)

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2022-09-27
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 2020-03-05
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多