Clips tensor values to a specified min and max.
Aliases:
tf.compat.v1.clip_by_valuetf.compat.v2.clip_by_value
tf.clip_by_value(
t,
clip_value_min,
clip_value_max,
name=None
)
Used in the tutorials:
AdversarialexampleusingFGSM``DeepDreamNeuralstyletransferGiven atensort,this operation returns atensor ofthe sametype and shape astwith its values clippedtoclip_value_minandclip_value_max. Any values lessthanclip_value_minare settoclip_value_min. Any values greaterthanclip_value_maxare settoclip_value_max.
For example:
A = tf.constant([[1, 20, 13], [3, 21, 13]])
B = tf.clip_by_value(A, clip_value_min=0, clip_value_max=3) # [[1, 3, 3],[3, 3, 3]]
C = tf.clip_by_value(A, clip_value_min=0., clip_value_max=3.) # throws `TypeError`
as input and clip_values are of different dtype
Args:
t: ATensororIndexedSlices.clip_value_min: A 0-D (scalar)Tensor, or aTensorwiththe same shape ast. The minimum valueto clip by.clip_value_max: A 0-D (scalar)Tensor, or aTensorwiththe same shape ast. The maximum valueto clip by.name: Anameforthe operation (optional).
Returns:
A clipped Tensor or IndexedSlices.
Raises:
ValueError: If the clip tensors would trigger array broadcasting that would make the returned tensor larger than the input.TypeError: If dtype of the inputisint32and dtype of theclip_value_min' orclip_value_maxisfloat32`