Skip to content

constraints

NonNegative

Bases: tf.keras.constraints.Constraint

Constraint that enforces positive activations.

__call__

1
__call__(w: tf.Tensor) -> tf.Tensor

Clips negative values of a provided weight tensor w to 0.0 and leaves positive values unchanged.

Parameters:

Name Type Description Default
w tf.Tensor

Tensor containing the wehights of a layer.

required

Returns:

Type Description
tf.Tensor

Tensor where negative values are clipped to 0.0.

Source code in DeepSaki/constraints/constraints.py
 7
 8
 9
10
11
12
13
14
15
16
def __call__(self, w: tf.Tensor) -> tf.Tensor:
    """Clips negative values of a provided weight tensor `w` to 0.0 and leaves positive values unchanged.

    Args:
        w (tf.Tensor): Tensor containing the wehights of a layer.

    Returns:
        Tensor where negative values are clipped to 0.0.
    """
    return w * tf.cast(tf.math.greater_equal(w, 0.0), w.dtype)