gradgraph.optimization.tf.constraints module
- class InBetween(lower_bound=None, upper_bound=None)[source]
Bases:
ConstraintConstrains the weights to be within a specified range.
This constraint clips the weights to lie within the specified lower and upper bounds.
- Parameters:
lower_bound (
floatorNone, optional) – The lower bound for the weights. If None, defaults to the smallest positive representable number for the current floating-point type (tf.keras.backend.epsilon()).upper_bound (
floatorNone, optional) – The upper bound for the weights. If None, defaults to the largest representable number for the current floating-point type.
- from_config(config)
Instantiates a constraint from a configuration dictionary.
Examples
>>> constraint = InBetween(lower_bound=0.0, upper_bound=1.0) >>> model.add(Dense(64, kernel_constraint=constraint))
Notes
This constraint is useful when you want to ensure that the weights of a layer remain within a certain range during training.
- classmethod from_config(config)
Instantiates a weight constraint from a configuration dictionary.
Example:
`python constraint = UnitNorm() config = constraint.get_config() constraint = UnitNorm.from_config(config) `- Args:
config: A Python dictionary, the output of get_config().
- Returns:
A keras.constraints.Constraint instance.