ReLU
類別tf_keras.layers.ReLU(max_value=None, negative_slope=0.0, threshold=0.0, **kwargs)
修正線性單元(Rectified Linear Unit)激活函數。
使用預設值時,它會逐元素回傳 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.
。