tfmot.clustering.keras.ClusterableLayer
Stay organized with collections
Save and categorize content based on your preferences.
Abstract Base Class for making your own keras layer clusterable.
Used in the notebooks
Your layer could be derived from a keras built-in layer or
it could be a keras custom layer.
The function get_clusterable_weights should be provided in both cases.
The function get_clusterable_algorithm is provided, when weights for
clustering is added in the keras layer.
Methods
get_clusterable_algorithm
View source
get_clusterable_algorithm(
weight_name
)
Returns class with the clustering algorithm for the given weight_name.
This function needs to be implemented for the customerable layers.
If the layer is derived from the built-in keras layer, the clustering
algorithm for the base built-in keras layer is used.
The returned class should be derived from ClusteringAlgorithm and
implements the function get_pulling_indices.
This function is used to provide a special lookup function for the custom
weights.
It reshapes and tile centroids the same way as the weights. This allows us
to find pulling indices efficiently.
Args |
weight_name
|
[string]
The name of the weight variable.
|
get_clusterable_weights
View source
@abc.abstractmethod
get_clusterable_weights()
Returns list of clusterable weight tensors.
All the weight tensors which the layer wants to be clustered during
training must be returned by this method.
Returns: List of weight tensors/kernels in the keras layer which must be
clustered during training. Each element in the list is a (name, kernel)
2-tuple that consists of the name of the clusterable kernel and the
kernel object itself.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-05-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-05-26 UTC."],[],[],null,["# tfmot.clustering.keras.ClusterableLayer\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/model-optimization/blob/v0.7.5/tensorflow_model_optimization/python/core/clustering/keras/clusterable_layer.py#L21-L66) |\n\nAbstract Base Class for making your own keras layer clusterable.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tfmot.clustering.keras.clusterable_layer.ClusterableLayer`](https://www.tensorflow.org/model_optimization/api_docs/python/tfmot/clustering/keras/ClusterableLayer)\n\n\u003cbr /\u003e\n\n### Used in the notebooks\n\n| Used in the guide |\n|------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Weight clustering comprehensive guide](https://www.tensorflow.org/model_optimization/guide/clustering/clustering_comprehensive_guide) |\n\nYour layer could be derived from a keras built-in layer or\nit could be a keras custom layer.\n\nThe function get_clusterable_weights should be provided in both cases.\n\nThe function get_clusterable_algorithm is provided, when weights for\nclustering is added in the keras layer.\n\nMethods\n-------\n\n### `get_clusterable_algorithm`\n\n[View source](https://github.com/tensorflow/model-optimization/blob/v0.7.5/tensorflow_model_optimization/python/core/clustering/keras/clusterable_layer.py#L49-L66) \n\n get_clusterable_algorithm(\n weight_name\n )\n\nReturns class with the clustering algorithm for the given weight_name.\n\nThis function needs to be implemented for the customerable layers.\nIf the layer is derived from the built-in keras layer, the clustering\nalgorithm for the base built-in keras layer is used.\n\nThe returned class should be derived from ClusteringAlgorithm and\nimplements the function get_pulling_indices.\nThis function is used to provide a special lookup function for the custom\nweights.\nIt reshapes and tile centroids the same way as the weights. This allows us\nto find pulling indices efficiently.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------------|----------------------------------------------------|\n| `weight_name` | `[string]` \u003cbr /\u003e The name of the weight variable. |\n\n\u003cbr /\u003e\n\n### `get_clusterable_weights`\n\n[View source](https://github.com/tensorflow/model-optimization/blob/v0.7.5/tensorflow_model_optimization/python/core/clustering/keras/clusterable_layer.py#L35-L47) \n\n @abc.abstractmethod\n get_clusterable_weights()\n\nReturns list of clusterable weight tensors.\n\nAll the weight tensors which the layer wants to be clustered during\ntraining must be returned by this method.\n\nReturns: List of weight tensors/kernels in the keras layer which must be\nclustered during training. Each element in the list is a (name, kernel)\n2-tuple that consists of the name of the clusterable kernel and the\nkernel object itself."]]