passion
passion

Reputation: 455

Does TFLiteConverter automatically quantize the Keras model?

I converted the trained Keras model using tf.lite.TFLiteConverter into tflite_model. Is the converted tflite_model quantized one? Here is the snippet to make the conversion.

import tensorflow as tf

keras_model = "./Trained_Models/h_vs_o_a_V1.h5"

converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_model)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

Upvotes: 0

Views: 250

Answers (1)

Shubham Panchal
Shubham Panchal

Reputation: 4289

Basically, we need the converter.post_training_quantize = True flag before the conversion takes place using converter.convert() like,

import tensorflow as tf

keras_model = "./Trained_Models/h_vs_o_a_V1.h5"

converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_model)
converter.post_training_quantize = True
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

Upvotes: 1

Related Questions