Clips tensor values to a maximum L2-norm.
Aliases:
tf.compat.v1.clip_by_normtf.compat.v2.clip_by_norm
tf.clip_by_norm(
t,
clip_norm,
axes=None,
name=None
)
Used in the guide:
EagerexecutionGiven atensort, and a maximum clip valueclip_norm,this operation normalizestsothatits L2-norm is lessthan or equaltoclip_norm, alongthe dimensions given inaxes. Specifically, inthe defaultcase where all dimensions are used for calculation, ifthe L2-norm oftis already lessthan or equaltoclip_norm,thentis notmodified. Ifthe L2-norm is greaterthanclip_norm,thenthis operation returns atensor ofthe sametype and shape astwith its values setto: t * clip_norm / l2norm(t) In this case, the L2-norm of the output tensor isclip_norm. As another example, iftis a matrix andaxes == [1],then each row ofthe outputwill have L2-norm lessthan or equaltoclip_norm. Ifaxes == [0]instead, each column ofthe outputwill be clipped. This operation is typically used to clip gradients before applying them with an optimizer.
Args:
t: ATensororIndexedSlices.clip_norm: A 0-D (scalar)Tensor> 0. A maximum clipping value.axes: A 1-D (vector)Tensoroftype int32 containingthe dimensionsto use for computingthe L2-norm. IfNone(the default), uses all dimensions.name: Anameforthe operation (optional).
Returns:
A clipped Tensor or IndexedSlices.
Raises:
ValueError: If the clip_norm tensor is not a 0-D scalar tensor.TypeError: If dtype of the input is not a floating point or complex type.