# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import tensorflow as tf
from tensorflow_model_optimization.quantization.keras import vitis_quantize
import numpy as np
from keras.preprocessing import image
from keras.preprocessing.image import ImageDataGenerator

model = tf.keras.models.load_model('classifier.h5')
quantizer = vitis_quantize.VitisQuantizer(model)

test_datagen = ImageDataGenerator(rescale = 1./255)
test_set = test_datagen.flow_from_directory('dataset/test_set',
                                            target_size = (64, 64),
                                            batch_size = 32,
                                            class_mode = 'binary')

# +

quantized_model = quantizer.quantize_model(calib_dataset = test_set)
# -

Quant_model_path = 'vitis-ai-quantized-cat_dog-classification-model.h5'

# Save the model
quantized_model.save(Quant_model_path)

from tensorflow_model_optimization.quantization.keras import vitis_quantize
with vitis_quantize.quantize_scope():
    quantized_model = tf.keras.models.load_model(Quant_model_path)
quantized_model

quantized_model.summary()

# !vai_c_tensorflow2 -h

# !vai_c_tensorflow2 -m vitis-ai-quantized-cat_dog-classification-model.h5 -a /opt/vitis_ai/compiler/arch/DPUCADX8G/ALVEO/arch.json -o vitis-compiled/ -n cat_dog_XIR



StarcoderdataJupyterScriptsDedupFiltered