Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tensorflow_addons/activations/hardshrink.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@keras_utils.register_keras_custom_object
@tf.function
def hardshrink(x, lower=-1.0, upper=1.0):
def hardshrink(x, lower=-0.5, upper=0.5):
"""Hard shrink function.

Computes hard shrink function:
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_addons/activations/hardshrink_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def test_invalid(self):
("float32", np.float32),
("float64", np.float64))
def test_hardshrink(self, dtype):
x = tf.constant([-2.0, -1.0, 0.0, 1.0, 2.0], dtype=dtype)
x = tf.constant([-2.0, -0.5, 0.0, 0.5, 2.0], dtype=dtype)
expected_result = tf.constant([-2.0, 0.0, 0.0, 0.0, 2.0], dtype=dtype)
self.assertAllCloseAccordingToType(hardshrink(x), expected_result)

expected_result = tf.constant([-2.0, -1.0, 0.0, 1.0, 2.0], dtype=dtype)
expected_result = tf.constant([-2.0, 0.0, 0.0, 0.0, 2.0], dtype=dtype)
self.assertAllCloseAccordingToType(
hardshrink(x, lower=-0.5, upper=0.5), expected_result)
hardshrink(x, lower=-1.0, upper=1.0), expected_result)

@parameterized.named_parameters(("float32", np.float32),
("float64", np.float64))
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_addons/activations/softshrink.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@keras_utils.register_keras_custom_object
@tf.function
def softshrink(x, lower=-1.0, upper=1.0):
def softshrink(x, lower=-0.5, upper=0.5):
"""Soft shrink function.

Computes soft shrink function:
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_addons/activations/softshrink_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def test_invalid(self):
("float64", np.float64))
def test_softshrink(self, dtype):
x = tf.constant([-2.0, -1.0, 0.0, 1.0, 2.0], dtype=dtype)
expected_result = tf.constant([-1.0, 0.0, 0.0, 0.0, 1.0], dtype=dtype)
expected_result = tf.constant([-1.5, -0.5, 0.0, 0.5, 1.5], dtype=dtype)
self.assertAllCloseAccordingToType(softshrink(x), expected_result)

expected_result = tf.constant([-1.5, -0.5, 0.0, 0.5, 1.5], dtype=dtype)
expected_result = tf.constant([-1.0, 0.0, 0.0, 0.0, 1.0], dtype=dtype)
self.assertAllCloseAccordingToType(
softshrink(x, lower=-0.5, upper=0.5), expected_result)
softshrink(x, lower=-1.0, upper=1.0), expected_result)

@parameterized.named_parameters(("float32", np.float32),
("float64", np.float64))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ REGISTER_OP("Addons>Hardshrink")
.Input("features: T")
.Output("activations: T")
.Attr("T: {half, float, double}")
.Attr("lower: float = -1.0")
.Attr("upper: float = 1.0")
.Attr("lower: float = -0.5")
.Attr("upper: float = 0.5")
.SetShapeFn(shape_inference::UnchangedShape);

REGISTER_OP("Addons>HardshrinkGrad")
.Input("gradients: T")
.Input("features: T")
.Output("backprops: T")
.Attr("T: {half, float, double}")
.Attr("lower: float = -1.0")
.Attr("upper: float = 1.0")
.Attr("lower: float = -0.5")
.Attr("upper: float = 0.5")
.SetShapeFn(shape_inference::MergeBothInputsShapeFn);

} // namespace addons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ REGISTER_OP("Addons>Softshrink")
.Input("features: T")
.Output("activations: T")
.Attr("T: {half, float, double}")
.Attr("lower: float = -1.0")
.Attr("upper: float = 1.0")
.Attr("lower: float = -0.5")
.Attr("upper: float = 0.5")
.SetShapeFn(shape_inference::UnchangedShape);

REGISTER_OP("Addons>SoftshrinkGrad")
.Input("gradients: T")
.Input("features: T")
.Output("backprops: T")
.Attr("T: {half, float, double}")
.Attr("lower: float = -1.0")
.Attr("upper: float = 1.0")
.Attr("lower: float = -0.5")
.Attr("upper: float = 0.5")
.SetShapeFn(shape_inference::MergeBothInputsShapeFn);

} // namespace addons
Expand Down