<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/sparsity/keras/pruning_schedule.py#L134-L177) |

Pruning schedule with constant sparsity(%) throughout training.

Inherits From: [`PruningSchedule`](https://www.tensorflow.org/model_optimization/api_docs/python/tfmot/sparsity/keras/PruningSchedule)

    tfmot.sparsity.keras.ConstantSparsity(
        target_sparsity, begin_step, end_step=-1, frequency=100
    )

### Used in the notebooks

| Used in the guide |
|---|
| - [Sparsity and cluster preserving quantization aware training (PCQAT) Keras example](https://www.tensorflow.org/model_optimization/guide/combine/pcqat_example) - [Pruning preserving quantization aware training (PQAT) Keras example](https://www.tensorflow.org/model_optimization/guide/combine/pqat_example) - [Sparsity preserving clustering Keras example](https://www.tensorflow.org/model_optimization/guide/combine/sparse_clustering_example) - [Sparse weights using structural pruning](https://www.tensorflow.org/model_optimization/guide/pruning/pruning_with_sparsity_2_by_4) |

<br />

<br />

<br />

| ## Args ||
|---|---|
| `target_sparsity` | A scalar float representing the target sparsity value. |
| `begin_step` | Step at which to begin pruning. |
| `end_step` | Step at which to end pruning. `-1` by default. `-1` implies continuing to prune till the end of training. |
| `frequency` | Only apply pruning every `frequency` steps. |

<br />

## Methods

### `from_config`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/sparsity/keras/pruning_schedule.py#L121-L131)

    @classmethod
    from_config(
        config
    )

Instantiates a `PruningSchedule` from its config.

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | Output of `get_config()`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `PruningSchedule` instance. ||

<br />

### `get_config`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/sparsity/keras/pruning_schedule.py#L168-L177)

    get_config()

### `__call__`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/sparsity/keras/pruning_schedule.py#L163-L166)

    __call__(
        step
    )

Returns the sparsity(%) to be applied.

If the returned sparsity(%) is 0, pruning is ignored for the step.

<br />

<br />

<br />

| Args ||
|---|---|
| `step` | Current step in graph execution. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Sparsity (%) that should be applied to the weights for the step. ||

<br />