ReLU
类tf_keras.layers.ReLU(max_value=None, negative_slope=0.0, threshold=0.0, **kwargs)
修正线性单元激活函数。
使用默认值时,它返回逐元素的 max(x, 0)
。
否则,它遵循以下公式:
f(x) = max_value if x >= max_value
f(x) = x if threshold <= x < max_value
f(x) = negative_slope * (x - threshold) otherwise
用法
>>> 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]
输入形状
任意。在模型中使用此层作为第一层时,请使用关键字参数 input_shape
(整数元组,不包括批处理轴)。
输出形状
与输入形状相同。
参数
None
。0.
。0.
。