<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/clustering/keras/clusterable_layer.py#L21-L66) |

Abstract Base Class for making your own keras layer clusterable.

#### View aliases


**Main aliases**

[`tfmot.clustering.keras.clusterable_layer.ClusterableLayer`](https://www.tensorflow.org/model_optimization/api_docs/python/tfmot/clustering/keras/ClusterableLayer)

<br />

### Used in the notebooks

| Used in the guide |
|---|
| - [Weight clustering comprehensive guide](https://www.tensorflow.org/model_optimization/guide/clustering/clustering_comprehensive_guide) |

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](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/clustering/keras/clusterable_layer.py#L49-L66)

    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.

<br />

<br />

<br />

| Args ||
|---|---|
| `weight_name` | `[string]` <br /> The name of the weight variable. |

<br />

### `get_clusterable_weights`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/clustering/keras/clusterable_layer.py#L35-L47)

    @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.