【问题标题】:Tensorflow model quantization best strategyTensorflow模型量化最佳策略
【发布时间】:2020-03-02 15:02:22
【问题描述】:

我对 Tensorflow 训练后量化过程感到困惑。官网参考Tensorflow Lite Quantization。不幸的是,这在我的情况下不起作用,也就是说,TFLiteConverter 为我的 Mask RCNN 模型返回错误:

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime and are not recognized by TensorFlow. If you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: <...>. Here is a list of operators for which you will need custom implementations: DecodeJpeg, StatelessWhile.

基本上,我已经尝试了TFLiteConverter 提供的所有可用选项,包括实验选项。我对这些错误并不感到惊讶,因为不支持移动设备的 decodejpeg 可能有意义,但是,我希望我的模型由 Tensorflow Serving 提供服务,因此我不知道为什么 Tensorflow Lite 是官方选择为了。 我也试过Graph Transform Tool,这似乎已被弃用,并发现了2个问题。首先,不可能用 bfloat16 或 float16 量化,只有 int8。其次,量化模型因误差而断裂:

Broadcast between [1,20,1,20,1,256] and [1,1,2,1,2,1] is not supported yet

在常规模型中什么不是问题。

此外,值得一提的是,我的模型最初是使用 Tensorflow 1.x 构建的,然后通过 tensorflow.compat.v1 移植到 Tensorflow 2.1。

这个问题占用了我大量的时间。如有任何提示,我将不胜感激。

【问题讨论】:

  • 同样的问题,很难相信仅仅为了在云端运行的性能和优化而没有选择量化模型,只有移动无处不在。

标签: python tensorflow quantization tensorflow-lite serving


【解决方案1】:

您可以将模型转换为 Tensorflow Lite 并使用 TF 中不受支持的操作(如 DecodeJpeg),这称为 SELECT TF OPS,请参阅指南here,了解如何在转换期间启用它。

【讨论】:

    猜你喜欢
    • 2015-05-20
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    相关资源
    最近更新 更多