Gustavo Sutter
Gustavo Sutter

Reputation: 94

TFLiteConverter parameters for optmization on TensorFlow 1.x

I've been learning about quantization on TensorFlow 2.x using TFLiteConverter, however I'm implementing a project on TensorFlow 1.13 and I'd like to know how to do the same things on this version.

For example, as far as I've observed the following commands do the same thing

# tf 1.x
converter.post_training_quantize = True

# tf 2.x
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]

Is it right? And what about integer quantization and quantization aware training, how to implement them?

Upvotes: 0

Views: 532

Answers (1)

Vishnuvardhan Janapati
Vishnuvardhan Janapati

Reputation: 3278

AFAIK, the following two are equivalent.

# tf 1.x
converter.post_training_quantize = True

# tf 2.x
converter.optimizations = [tf.lite.Optimize.DEFAULT]

converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] is used for full integer quantization.

Please note that post training quantization is simple when compared to quantization aware training (QAT) but QAT provides higher model accuracy. Generally it is suggested to use post training quantization. If the performance of post training quantization doesn't meet your requirements, then go for QAT.

As you might have already know, there are several levels of quantizations can be done to optimize for size and performance. The following guide covers full integer quantization and other techniques (float quantization, float16 quantization etc)

https://www.tensorflow.org/lite/performance/model_optimization

Here is the best resource to follow on the guidelines of QAT.

https://www.tensorflow.org/model_optimization/guide/quantization/training

Upvotes: 1

Related Questions