为什么解量化节点无法准备?

2024-04-26 21:28:55 发布

您现在位置:Python中文网/ 问答频道 /正文

背景

我正在使用MediaPipe进行手动跟踪,发现这个wrapper对于加载MediaPipe的hand_landmark.tflite模型非常有用。对于我来说,在使用Tensorflow 1.14.0的Ubuntu18.04上工作没有任何问题

但是,当我尝试使用最新发布的model时,遇到以下错误:

INFO: Initialized TensorFlow Lite runtime.
Traceback (most recent call last):
  File "/home/user/code/.../repo/models/test_model.py", line 12, in <module>
    use_mediapipe_model()
  File "/home/user/code/.../repo/models/test_model.py", line 8, in use_mediapipe_model
    interp_joint.allocate_tensors()
  File "/home/user/code/env/lib/python3.6/site-packages/tensorflow/lite/python/interpreter.py", line 95, in allocate_tensors
    return self._interpreter.AllocateTensors()
  File "/home/user/code/env/lib/python3.6/site-packages/tensorflow/lite/python/interpreter_wrapper/tensorflow_wrap_interpreter_wrapper.py", line 106, in AllocateTensors
    return _tensorflow_wrap_interpreter_wrapper.InterpreterWrapper_AllocateTensors(self)
RuntimeError: tensorflow/lite/kernels/dequantize.cc:62 op_context.input->type == kTfLiteUInt8 || op_context.input->type == kTfLiteInt8 was not true.Node number 0 (DEQUANTIZE) failed to prepare.

当查看Netron中的两个模型时,我可以看到较新的模型使用了Dequantize类型的节点,这似乎导致了问题。由于我是Tensorflow的初学者,所以我真的不知道该从这里走到哪里

再现错误的代码

from pathlib import Path
import tensorflow as tf


def use_mediapipe_model():
    interp_joint = tf.lite.Interpreter(
        f"{Path(__file__).parent}/hand_landmark.tflite") # path to model
    interp_joint.allocate_tensors()


if __name__ == "__main__":
    use_mediapipe_model()

问题

问题是与我正在使用的Tensorflow版本有关,还是在加载.tflite模型时我做错了什么


Tags: inpy模型homemodelusetensorflowline