float_model = tf.keras.models.load_model(‘float_model.h5’)
from tensorflow_model_optimization.quantization.keras import vitis_quantize
quantizer = vitis_quantize.VitisQuantizer(float_model)
quantized_model = quantizer.quantize_model(calib_dataset=calib_dataset)
Here, "calib_dataset"
is used as a
representative calibration dataset for calibration as an example. You can use full or
part of eval_dataset
, train_dataset
, or other
datasets. You can also use train_dataset
or other datasets. The
quantizer reads the whole dataset to calibrate it. If you use the tf.data.Dataset
object, the batch size is controlled by the dataset
itself. If you use the numpy.array
object, the default
batch size is 50.