Closed MATTYGILO closed 2 years ago
Ok I've fixed the problem using this code:
def cluster_model(model):
# Info required for clustering
cluster_weights = tfmot.clustering.keras.cluster_weights
CentroidInitialization = tfmot.clustering.keras.CentroidInitialization
clustering_params = {
'number_of_clusters': 16,
'cluster_centroids_init': CentroidInitialization.LINEAR
}
def apply_clustering_to_dense(layer):
accepted_layers = [
tf.keras.layers.Dense,
tf.keras.layers.GlobalAveragePooling2D,
tf.keras.layers.ReLU,
tf.keras.layers.Conv2D,
tf.keras.layers.BatchNormalization,
tf.keras.layers.DepthwiseConv2D,
tf.keras.layers.Activation,
]
for accepted in accepted_layers:
if isinstance(layer, accepted):
return cluster_weights(layer, **clustering_params)
return layer
return tf.keras.models.clone_model(
model,
clone_function=apply_clustering_to_dense,
)
Prior to filing: check that this should be a bug instead of a feature request. Everything supported, including the compatible versions of TensorFlow, is listed in the overview page of each technique. For example, the overview page of quantization-aware training is here. An issue for anything not supported should be a feature request.
Describe the bug I am using clustering to reduce the size of a yamnet model
System information
TensorFlow version (installed from source or binary): 2.7.0
TensorFlow Model Optimization version (installed from source or binary): Installed using wheel from GitHub on an m1 Mac
Python version: 3.10
Describe the expected behavior
final_model = tfmot.clustering.keras.strip_clustering(clustered_model)
Strip the clustered modelDescribe the current behavior Failing with this error
Code to reproduce the issue
Similar problem. Mine is for clustering though:
867