【问题标题】:Is it possible to quantize a tflite model?是否可以量化 tflite 模型?
【发布时间】:2018-06-19 08:20:32
【问题描述】:

我有一个 .pb 模型,我想将其用作自定义 MLKit 模型。 MLKit 仅支持 .tflite 模型,但即使在我使用 toco 获取 TensorFlow Lite 模型之后,文件大小对于 Firebase 来说还是太大(95 MB,只允许 40 MB)。

有没有办法量化图然后转换为 TFLite 或量化 .tflite 图?

当我执行前者时,我收到以下错误消息:Unsupported TensorFlow op: Dequantize) for which the quantized form is not yet implemented. Sorry, and patches welcome (that's a relatively fun patch to write, mostly providing the actual quantized arithmetic code for this op).

【问题讨论】:

    标签: android tensorflow tensorflow-lite firebase-mlkit


    【解决方案1】:

    由于您主要对减小模型大小感兴趣,因此可以将 --optimizations=[tf.lite.Optimizations.DEFAULT] 标志传递给 TOCO。这应该以 8 位存储权重并在推理期间进行去量化以进行浮点计算。根据模型和问题,这可能会影响准确性,因此请在结果模型上运行 eval 并确保其达到您所需的标准。

    如果您想使用整数计算运行模型,您可以使用量化进行训练,然后使用 TOCO 将结果图转换为 TFLite,使用以下训练重写:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/quantize

    这有点复杂,涉及在冻结并提供给 TOCO 之前对您的 tensorflow 模型进行一些重新训练。

    【讨论】:

    • 当我运行它时,使用这个标志会产生一个零 KB 图表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多