【发布时间】:2021-09-24 11:34:34
【问题描述】:
TFLite 模型转换允许自动量化或反量化模型的输入或输出。您可以像这样适当地设置inference_input_type 和inference_output_type 来做到这一点。
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_data_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
但是,根据 TensorFlow 2.7 TFLite models finally support multiple signatures。这些可以从保存的模型、Keras 模型或具体函数中自动检索。然而,这提出了一个问题:如何在签名级别为输入和输出设置量化/去量化?此外,如果一个签名有多个输入或输出,你怎么做?
似乎inference_input_type 和inference_output_type 仅限于模型通过其调用方法导出的任何单输入(可能也是单输出?)函数。任何关于如何处理不同签名中特定参数的量化/去量化的提示,即使是手动的,都将受到欢迎。
【问题讨论】:
-
一点更新。我发现在多个签名的情况下,
representative_dataset(我也想inference_input_type和inference_output_type)针对的签名是第一个按字母顺序您从具体函数列表转换。它确实取决于您的函数的名称。 TF 开发人员:这确实需要改进设计。
标签: tensorflow tensorflow-lite quantization