Missed TensorFlow World? Check out the recap. Learn more

tfmot.sparsity.keras.ConstantSparsity

View source on GitHub

Class ConstantSparsity

Pruning schedule with constant sparsity(%) throughout training.

Inherits From: PruningSchedule

__init__

View source

__init__(
    target_sparsity,
    begin_step,
    end_step=-1,
    frequency=100
)

Initializes a Pruning schedule with constant sparsity.

Sparsity is applied in the interval [begin_step, end_step] every frequency steps. At each applicable step, the sparsity(%) is constant.

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.

Methods

__call__

View source

__call__(step)

Returns the sparsity(%) to be applied.

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

Args:

  • step: Current step in graph execution.

Returns:

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

from_config

View source

from_config(
    cls,
    config
)

Instantiates a PruningSchedule from its config.

Args:

  • config: Output of get_config().

Returns:

A PruningSchedule instance.

get_config

View source

get_config()