Fix a number of deserialization error messages. While `print(string, obj)` is valid syntax, `ValueError(string, obj)` is not.
PiperOrigin-RevId: 309877228
Change-Id: Id6f7f8b0207a0c432c232c3bf4c80eb6c1ae5471
diff --git a/tensorflow/python/keras/activations.py b/tensorflow/python/keras/activations.py
index 1b68f42..34d04d6 100644
--- a/tensorflow/python/keras/activations.py
+++ b/tensorflow/python/keras/activations.py
@@ -487,4 +487,4 @@
else:
raise TypeError(
'Could not interpret activation function identifier: {}'.format(
- repr(identifier)))
+ identifier))
diff --git a/tensorflow/python/keras/losses.py b/tensorflow/python/keras/losses.py
index 32a6703..dfd5e41 100644
--- a/tensorflow/python/keras/losses.py
+++ b/tensorflow/python/keras/losses.py
@@ -1880,8 +1880,8 @@
elif callable(identifier):
return identifier
else:
- raise ValueError('Could not interpret '
- 'loss function identifier:', identifier)
+ raise ValueError(
+ 'Could not interpret loss function identifier: {}'.format(identifier))
LABEL_DTYPES_FOR_LOSSES = {
diff --git a/tensorflow/python/keras/losses_test.py b/tensorflow/python/keras/losses_test.py
index c57ac97..5b3bb5a 100644
--- a/tensorflow/python/keras/losses_test.py
+++ b/tensorflow/python/keras/losses_test.py
@@ -234,6 +234,10 @@
with self.assertRaisesRegexp(ValueError, 'Invalid Reduction Key Bar.'):
mse_obj(y, y)
+ def test_deserialization_error(self):
+ with self.assertRaisesRegex(ValueError, 'Could not interpret loss'):
+ losses.get(0)
+
@combinations.generate(combinations.combine(mode=['graph', 'eager']))
class MeanSquaredErrorTest(test.TestCase):
diff --git a/tensorflow/python/keras/metrics.py b/tensorflow/python/keras/metrics.py
index 4bac568..63cf7c5 100644
--- a/tensorflow/python/keras/metrics.py
+++ b/tensorflow/python/keras/metrics.py
@@ -3479,9 +3479,8 @@
elif callable(identifier):
return identifier
else:
- error_msg = 'Could not interpret metric function identifier: {}'.format(
- identifier)
- raise ValueError(error_msg)
+ raise ValueError(
+ 'Could not interpret metric function identifier: {}'.format(identifier))
def is_built_in(cls):
diff --git a/tensorflow/python/keras/optimizers.py b/tensorflow/python/keras/optimizers.py
index f218681..5d8e135 100644
--- a/tensorflow/python/keras/optimizers.py
+++ b/tensorflow/python/keras/optimizers.py
@@ -899,4 +899,5 @@
config = {'class_name': str(identifier), 'config': {}}
return deserialize(config)
else:
- raise ValueError('Could not interpret optimizer identifier:', identifier)
+ raise ValueError(
+ 'Could not interpret optimizer identifier: {}'.format(identifier))
diff --git a/tensorflow/python/keras/optimizers_test.py b/tensorflow/python/keras/optimizers_test.py
index c178c8c..db051ea 100644
--- a/tensorflow/python/keras/optimizers_test.py
+++ b/tensorflow/python/keras/optimizers_test.py
@@ -253,6 +253,9 @@
batch_size=5,
verbose=0)
+ def test_deserialization_error(self):
+ with self.assertRaisesRegex(ValueError, 'Could not interpret optimizer'):
+ keras.optimizers.get(0)
if __name__ == '__main__':
test.main()
diff --git a/tensorflow/python/keras/regularizers.py b/tensorflow/python/keras/regularizers.py
index b4d1248..973d916 100644
--- a/tensorflow/python/keras/regularizers.py
+++ b/tensorflow/python/keras/regularizers.py
@@ -312,4 +312,5 @@
elif callable(identifier):
return identifier
else:
- raise ValueError('Could not interpret regularizer identifier:', identifier)
+ raise ValueError(
+ 'Could not interpret regularizer identifier: {}'.format(identifier))
diff --git a/tensorflow/python/keras/regularizers_test.py b/tensorflow/python/keras/regularizers_test.py
index b88cd08..b10218b 100644
--- a/tensorflow/python/keras/regularizers_test.py
+++ b/tensorflow/python/keras/regularizers_test.py
@@ -199,6 +199,10 @@
# - 4 from activity regularizers on the shared_dense layer.
self.assertLen(model.losses, 9)
+ def test_deserialization_error(self):
+ with self.assertRaisesRegex(ValueError, 'Could not interpret regularizer'):
+ keras.regularizers.get(0)
+
if __name__ == '__main__':
test.main()