Add TF-specific tests for ReLU layer.
import pytest
from keras.utils.test_utils import layer_test
from keras import layers
+from keras import backend as K
def test_leaky_relu():
@@ -42,6 +43,12 @@ def test_relu():
'negative_slope': 0.2,
'threshold': 3.0},
input_shape=(2, 3, 4))
+ layer_test(layers.ReLU,
+ kwargs={'max_value': 6},
+ input_shape=(2, 3, 4))
+ layer_test(layers.ReLU,
+ kwargs={'negative_slope': 0.2},
+ input_shape=(2, 3, 4))
# max_value of ReLU layer cannot be negative value
with pytest.raises(ValueError):
@@ -54,5 +61,20 @@ def test_relu():
input_shape=(2, 3, 4))
+@pytest.mark.skipif((K.backend() != 'tensorflow'),
+ reason='TF-specific implementation.')
+def test_relu_tf_ops():
+ inputs = layers.Input((3,))
+ # Test that `relu` op gets used.
+ outputs = layers.ReLU()(inputs)
+ assert outputs.op.name.lower().endswith('/relu')
+ # Test that `leakyrelu` op gets used.
+ outputs = layers.ReLU(negative_slope=0.2)(inputs)
+ assert outputs.op.name.lower().endswith('/leakyrelu')
+ # Test that `relu6` op gets used.
+ outputs = layers.ReLU(max_value=6)(inputs)
+ assert outputs.op.name.lower().endswith('/relu6')
+
+
if __name__ == '__main__':
pytest.main([__file__])
