提交 91f8e450 编写于 作者: F Francois Chollet

Add TF-specific tests for ReLU layer.

上级 6fb50697
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__])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册