Tensorflow模型量化的最佳策略



我对Tensorflow训练后的量化过程感到困惑。官方网站指的是Tensorflow Lite量化。不幸的是,这在我的情况下不起作用,也就是说,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提供的所有可用选项,包括实验选项。我对这些错误并不感到惊讶,因为不支持移动设备的解码jpeg可能是有意义的,然而,我希望我的模型由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。

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

您可以将模型转换为Tensorflow Lite,并使用TF中不支持的操作(如DecodeJpeg(,这被称为SELECT TF ops,请参阅此处关于如何在转换过程中启用它的指南。

最新更新