Add lowercase aliases for some regularizers for backwards compatibility. (#304)
Also fix assertion in regularizers unit tests.
This commit is contained in:
parent
980d329f1c
commit
c2abf535e1
@ -212,7 +212,7 @@ class L1L2(Regularizer):
|
||||
return {"l1": float(self.l1), "l2": float(self.l2)}
|
||||
|
||||
|
||||
@keras_core_export("keras_core.regularizers.L1")
|
||||
@keras_core_export(["keras_core.regularizers.L1", "keras_core.regularizers.l1"])
|
||||
class L1(Regularizer):
|
||||
"""A regularizer that applies a L1 regularization penalty.
|
||||
|
||||
@ -241,7 +241,7 @@ class L1(Regularizer):
|
||||
return {"l1": float(self.l1)}
|
||||
|
||||
|
||||
@keras_core_export("keras_core.regularizers.L2")
|
||||
@keras_core_export(["keras_core.regularizers.L2", "keras_core.regularizers.l2"])
|
||||
class L2(Regularizer):
|
||||
"""A regularizer that applies a L2 regularization penalty.
|
||||
|
||||
@ -270,7 +270,12 @@ class L2(Regularizer):
|
||||
return {"l2": float(self.l2)}
|
||||
|
||||
|
||||
@keras_core_export("keras_core.regularizers.OrthogonalRegularizer")
|
||||
@keras_core_export(
|
||||
[
|
||||
"keras_core.regularizers.OrthogonalRegularizer",
|
||||
"keras_core.regularizers.orthogonal_regularizer",
|
||||
]
|
||||
)
|
||||
class OrthogonalRegularizer(Regularizer):
|
||||
"""Regularizer that encourages input vectors to be orthogonal to each other.
|
||||
|
||||
|
@ -35,7 +35,16 @@ class RegularizersTest(testing.TestCase):
|
||||
|
||||
def test_get_method(self):
|
||||
obj = regularizers.get("l1l2")
|
||||
self.assertTrue(obj, regularizers.L1L2)
|
||||
self.assertIsInstance(obj, regularizers.L1L2)
|
||||
|
||||
obj = regularizers.get("l1")
|
||||
self.assertIsInstance(obj, regularizers.L1)
|
||||
|
||||
obj = regularizers.get("l2")
|
||||
self.assertIsInstance(obj, regularizers.L2)
|
||||
|
||||
obj = regularizers.get("orthogonal_regularizer")
|
||||
self.assertIsInstance(obj, regularizers.OrthogonalRegularizer)
|
||||
|
||||
obj = regularizers.get(None)
|
||||
self.assertEqual(obj, None)
|
||||
|
Loading…
Reference in New Issue
Block a user