MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / relu

Function relu

tensorflow/python/keras/backend.py:4210–4259  ·  view source on GitHub ↗

Rectified linear unit. With default values, it returns element-wise `max(x, 0)`. Otherwise, it follows: `f(x) = max_value` for `x >= max_value`, `f(x) = x` for `threshold <= x < max_value`, `f(x) = alpha * (x - threshold)` otherwise. Arguments: x: A tensor or variable. alp

(x, alpha=0., max_value=None, threshold=0)

Source from the content-addressed store, hash-verified

4208
4209@keras_export('keras.backend.relu')
4210def relu(x, alpha=0., max_value=None, threshold=0):
4211 """Rectified linear unit.
4212
4213 With default values, it returns element-wise `max(x, 0)`.
4214
4215 Otherwise, it follows:
4216 `f(x) = max_value` for `x >= max_value`,
4217 `f(x) = x` for `threshold <= x < max_value`,
4218 `f(x) = alpha * (x - threshold)` otherwise.
4219
4220 Arguments:
4221 x: A tensor or variable.
4222 alpha: A scalar, slope of negative section (default=`0.`).
4223 max_value: float. Saturation threshold.
4224 threshold: float. Threshold value for thresholded activation.
4225
4226 Returns:
4227 A tensor.
4228 """
4229
4230 if alpha != 0.:
4231 if max_value is None and threshold == 0:
4232 return nn.leaky_relu(x, alpha=alpha)
4233
4234 if threshold != 0:
4235 negative_part = nn.relu(-x + threshold)
4236 else:
4237 negative_part = nn.relu(-x)
4238
4239 clip_max = max_value is not None
4240
4241 if threshold != 0:
4242 # computes x for x > threshold else 0
4243 x = x * math_ops.cast(math_ops.greater(x, threshold), floatx())
4244 elif max_value == 6:
4245 # if no threshold, then can use nn.relu6 native TF op for performance
4246 x = nn.relu6(x)
4247 clip_max = False
4248 else:
4249 x = nn.relu(x)
4250
4251 if clip_max:
4252 max_value = _constant_to_tensor(max_value, x.dtype.base_dtype)
4253 zero = _constant_to_tensor(0., x.dtype.base_dtype)
4254 x = clip_ops.clip_by_value(x, zero, max_value)
4255
4256 if alpha != 0.:
4257 alpha = _to_tensor(alpha, x.dtype.base_dtype)
4258 x -= alpha * negative_part
4259 return x
4260
4261
4262@keras_export('keras.backend.elu')

Callers 7

_TestFoldConv2dMethod · 0.50
_TestFoldAtrousConv2dMethod · 0.50
callMethod · 0.50

Calls 6

floatxFunction · 0.85
_constant_to_tensorFunction · 0.85
_to_tensorFunction · 0.85
greaterMethod · 0.80
relu6Method · 0.80
castMethod · 0.45

Tested by 6

_TestFoldConv2dMethod · 0.40
_TestFoldAtrousConv2dMethod · 0.40