Clips tensor values to a specified min and max.
Aliases:
tf.compat.v1.clip_by_value
tf.compat.v2.clip_by_value
tf.clip_by_value(
t,
clip_value_min,
clip_value_max,
name=None
)
Used in the tutorials:
A
dv
er
sa
ri
al
e
xa
mp
le
u
si
ng
F
GS
M``D
ee
pD
re
am
N
eu
ra
ls
t
yl
et
r
an
sf
er
Given at
ensort
,t
his operat
ion ret
urns at
ensor oft
he samet
ype and shape ast
wit
h it
s values clippedt
oclip_value_min
andclip_value_max
. Any values lesst
hanclip_value_min
are set
t
oclip_value_min
. Any values great
ert
hanclip_value_max
are set
t
oclip_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
: ATensor
orIndexedSlices
.clip_value_min
: A 0-D (scalar)Tensor
, or aTensor
wit
ht
he same shape ast
. The minimum valuet
o clip by.clip_value_max
: A 0-D (scalar)Tensor
, or aTensor
wit
ht
he same shape ast
. The maximum valuet
o clip by.name
: Aname
fort
he operat
ion (opt
ional).
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 inputis
int32
and dtype of theclip_value_min' or
clip_value_maxis
float32`