tf.keras.layers.ReLU
Stay organized with collections
Save and categorize content based on your preferences.
Rectified Linear Unit activation function.
Inherits From: Layer
tf.keras.layers.ReLU(
max_value=None, negative_slope=0, threshold=0, **kwargs
)
With default values, it returns element-wise max(x, 0)
.
Otherwise, it follows:
f(x) = max_value if x >= max_value
f(x) = x if threshold <= x < max_value
f(x) = negative_slope * (x - threshold) otherwise
Usage:
layer = tf.keras.layers.ReLU()
output = layer([-3.0, -1.0, 0.0, 2.0])
list(output.numpy())
[0.0, 0.0, 0.0, 2.0]
layer = tf.keras.layers.ReLU(max_value=1.0)
output = layer([-3.0, -1.0, 0.0, 2.0])
list(output.numpy())
[0.0, 0.0, 0.0, 1.0]
layer = tf.keras.layers.ReLU(negative_slope=1.0)
output = layer([-3.0, -1.0, 0.0, 2.0])
list(output.numpy())
[-3.0, -1.0, 0.0, 2.0]
layer = tf.keras.layers.ReLU(threshold=1.5)
output = layer([-3.0, -1.0, 1.0, 2.0])
list(output.numpy())
[0.0, 0.0, 0.0, 2.0]
Arbitrary. Use the keyword argument input_shape
(tuple of integers, does not include the batch axis)
when using this layer as the first layer in a model.
Output shape:
Same shape as the input.
Arguments |
max_value
|
Float >= 0. Maximum activation value. Default to None, which
means unlimited.
|
negative_slope
|
Float >= 0. Negative slope coefficient. Default to 0.
|
threshold
|
Float. Threshold value for thresholded activation. Default to 0.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.layers.ReLU\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/layers/ReLU) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/python/keras/layers/advanced_activations.py#L297-L382) |\n\nRectified Linear Unit activation function.\n\nInherits From: [`Layer`](../../../tf/keras/layers/Layer)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.layers.ReLU`](/api_docs/python/tf/keras/layers/ReLU)\n\n\u003cbr /\u003e\n\n tf.keras.layers.ReLU(\n max_value=None, negative_slope=0, threshold=0, **kwargs\n )\n\nWith default values, it returns element-wise `max(x, 0)`.\n\nOtherwise, it follows: \n\n f(x) = max_value if x \u003e= max_value\n f(x) = x if threshold \u003c= x \u003c max_value\n f(x) = negative_slope * (x - threshold) otherwise\n\n#### Usage:\n\n layer = tf.keras.layers.ReLU()\n output = layer([-3.0, -1.0, 0.0, 2.0])\n list(output.numpy())\n [0.0, 0.0, 0.0, 2.0]\n layer = tf.keras.layers.ReLU(max_value=1.0)\n output = layer([-3.0, -1.0, 0.0, 2.0])\n list(output.numpy())\n [0.0, 0.0, 0.0, 1.0]\n layer = tf.keras.layers.ReLU(negative_slope=1.0)\n output = layer([-3.0, -1.0, 0.0, 2.0])\n list(output.numpy())\n [-3.0, -1.0, 0.0, 2.0]\n layer = tf.keras.layers.ReLU(threshold=1.5)\n output = layer([-3.0, -1.0, 1.0, 2.0])\n list(output.numpy())\n [0.0, 0.0, 0.0, 2.0]\n\n#### Input shape:\n\nArbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the batch axis)\nwhen using this layer as the first layer in a model.\n\n#### Output shape:\n\nSame shape as the input.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|------------------|--------------------------------------------------------------------------------|\n| `max_value` | Float \\\u003e= 0. Maximum activation value. Default to None, which means unlimited. |\n| `negative_slope` | Float \\\u003e= 0. Negative slope coefficient. Default to 0. |\n| `threshold` | Float. Threshold value for thresholded activation. Default to 0. |\n\n\u003cbr /\u003e"]]