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

Function hard_sigmoid

tensorflow/python/keras/backend.py:4501–4519  ·  view source on GitHub ↗

Segment-wise linear approximation of sigmoid. Faster than sigmoid. Returns `0.` if `x < -2.5`, `1.` if `x > 2.5`. In `-2.5 <= x <= 2.5`, returns `0.2 * x + 0.5`. Arguments: x: A tensor or variable. Returns: A tensor.

(x)

Source from the content-addressed store, hash-verified

4499
4500@keras_export('keras.backend.hard_sigmoid')
4501def hard_sigmoid(x):
4502 """Segment-wise linear approximation of sigmoid.
4503
4504 Faster than sigmoid.
4505 Returns `0.` if `x < -2.5`, `1.` if `x > 2.5`.
4506 In `-2.5 <= x <= 2.5`, returns `0.2 * x + 0.5`.
4507
4508 Arguments:
4509 x: A tensor or variable.
4510
4511 Returns:
4512 A tensor.
4513 """
4514 point_two = _constant_to_tensor(0.2, x.dtype.base_dtype)
4515 point_five = _constant_to_tensor(0.5, x.dtype.base_dtype)
4516 x = math_ops.mul(x, point_two)
4517 x = math_ops.add(x, point_five)
4518 x = clip_ops.clip_by_value(x, 0., 1.)
4519 return x
4520
4521
4522@keras_export('keras.backend.tanh')

Callers 1

test_hard_sigmoidMethod · 0.70

Calls 3

_constant_to_tensorFunction · 0.85
mulMethod · 0.45
addMethod · 0.45

Tested by 1

test_hard_sigmoidMethod · 0.56