tensorflow / model-optimization

A toolkit to optimize ML models for deployment for Keras and TensorFlow, including quantization and pruning.
https://www.tensorflow.org/model_optimization
Apache License 2.0
1.48k stars 320 forks source link

Cannot use Quantize layer and use abstract class and methods #1122

Open dhruven-god opened 4 months ago

dhruven-god commented 4 months ago

I am trying to Quantize the whole model but whenever, I try to load the model using quantized scope it gives me error like this

import sys, os
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
import tensorflow_model_optimization as tfmot
from tensorflow.keras.utils import CustomObjectScope

customObjects = {'DefaultQuantizeConfig': tfmot.quantization.keras.QuantizeConfig}       
with tfmot.quantization.keras.quantize_scope(customObjects):
    loaded_model = load_model('UpdtQuant.h5')
image

Also, when I try to define scope it gives me unknown value error: Quantize layer is not defined

Can someone help me with this issue?

tucan9389 commented 3 months ago

@dhruven-god

Thanks for reporting.

Could you provide fully reproducible script? (colab is recommended or complete python script with tf, tfmot version specification is also fine) If you can share your UpdtQuant.h5 model (or another model that can reproduce this error), it would be helpful.