简体   繁体   English

量化的 TFLite 模型比 TF 模型具有更好的准确性

[英]Quantized TFLite model gives better accuracy than TF model

I am developing an end-to-end training and quantization aware traing example.我正在开发一个端到端的训练量化感知训练示例。 Using the CIFAR 10 dataset, I load a pretrained MobilenetV2 model and then use the code from the TensorFlow Guide to quantize my model.使用CIFAR 10数据集,我加载了一个预训练的MobilenetV2模型,然后使用 TensorFlow 指南中的代码来量化我的模型。 After the whole process finishes properly, I get the following results:整个过程正确完成后,我得到以下结果:

Quant TFLite test_accuracy: 0.94462
Quant TF test accuracy:     0.744700014591217
TF test accuracy:           0.737500011920929

I wonder, how is this possible?我想知道,这怎么可能? Quantization is supposed to reduce accuracy a little bit.量化应该会稍微降低准确性

I have noticed that in the TensorFlow's Guide example, accuracy is also enhanced a little bit, but very little compared to my example.我注意到在 TensorFlow's Guide 示例中,准确性也有所提高,但与我的示例相比非常小。 To be more specific, when running this code which uses mnist dataset, I get the results below, which are acceptable by the developers of TensorFlow, as they mention that there is no change in accuracy .更具体地说,当运行这个使用mnist数据集的代码时,我得到了下面的结果,这是 TensorFlow 的开发人员可以接受的,因为他们提到准确度没有变化

Quant TFLite test_accuracy: 0.9817
Quant TF test accuracy:     0.9815
TF test accuracy:           0.9811

Note that I haven't changed the code I attached from the TensorFlow Guide, I just use a different dataset and model .请注意,我没有更改从 TensorFlow 指南中附加的代码,我只是使用了不同的datasetmodel

This can be possible when your model is not fully converged and also the size of your test dataset is not considered as big enough to differ those 2. In addition, even your model is converged, the way of reducing bit inference sometimes can help the range of random variable in each node is limited and sometimes can match your case and help the gradient find the optimal point better.当您的模型没有完全收敛并且您的测试数据集的大小不足以区分这两个时,这可能是可能的。 此外,即使您的模型已经收敛,减少位推理的方法有时也有助于范围每个节点中随机变量的数量是有限的,有时可以匹配您的情况并帮助梯度更好地找到最佳点。 However, I still encourage you to expand your test set, and check the model convergence because the gap is way too much.但是,我仍然鼓励您扩展您的测试集,并检查模型收敛性,因为差距太大了。

A solid proof for you can be the classification from amazon when they reduce float32 to float16.当他们将 float32 减少到 float16 时,亚马逊的分类可以为您提供可靠的证据。 The accuracy increase准确率提高在此处输入图片说明

Furthermore, for MNIST, the data is simple and the accuracy is not really much different when it is just around 0.9815 as mean with a little variance.此外,对于 MNIST,数据很简单,当它只是在 0.9815 左右作为平均值时,准确度并没有太大的不同,但有一点差异。 To my understanding, this is reasonable.在我看来,这是合理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM