Improve error messages of SavedModel utils and tools.
@@ -134,8 +134,9 @@ class ClassificationOutput(ExportOutput):
raise ValueError('Classification classes must be a string Tensor; '
'got {}'.format(classes))
if scores is None and classes is None:
- raise ValueError('At least one of scores and classes must be set.')
-
+ raise ValueError('Cannot create a ClassificationOutput with empty '
+ 'arguments. At least one of `scores` and `classes` '
+ 'must be defined.')
self._scores = scores
self._classes = classes
@@ -149,12 +150,22 @@ class ClassificationOutput(ExportOutput):
def as_signature_def(self, receiver_tensors):
if len(receiver_tensors) != 1:
- raise ValueError('Classification input must be a single string Tensor; '
- 'got {}'.format(receiver_tensors))
+ raise ValueError(
+ 'Classification signatures can only accept a single tensor input of '
+ 'type tf.string. Please check to make sure that you have structured '
+ 'the serving_input_receiver_fn so that it creates a single string '
+ 'placeholder. If your model function expects multiple inputs, then '
+ 'use `tf.io.parse_example()` to parse the string into multiple '
+ f'tensors.\n Received: {receiver_tensors}')
(_, examples), = receiver_tensors.items()
if tf.as_dtype(examples.dtype) != tf.string:
- raise ValueError('Classification input must be a single string Tensor; '
- 'got {}'.format(receiver_tensors))
+ raise ValueError(
+ 'Classification signatures can only accept a single tensor input of '
+ 'type tf.string. Please check to make sure that you have structured '
+ 'the serving_input_receiver_fn so that it creates a single string '
+ 'placeholder. If your model function expects multiple inputs, then '
+ 'use `tf.io.parse_example()` to parse the string into multiple '
+ f'tensors.\n Received: {receiver_tensors}')
return tf.compat.v1.saved_model.classification_signature_def(
examples, self.classes, self.scores)
@@ -182,12 +193,22 @@ class RegressionOutput(ExportOutput):
def as_signature_def(self, receiver_tensors):
if len(receiver_tensors) != 1:
- raise ValueError('Regression input must be a single string Tensor; '
- 'got {}'.format(receiver_tensors))
+ raise ValueError(
+ 'Regression signatures can only accept a single tensor input of '
+ 'type tf.string. Please check to make sure that you have structured '
+ 'the serving_input_receiver_fn so that it creates a single string '
+ 'placeholder. If your model function expects multiple inputs, then '
+ 'use `tf.io.parse_example()` to parse the string into multiple '
+ f'tensors.\n Received: {receiver_tensors}')
(_, examples), = receiver_tensors.items()
if tf.as_dtype(examples.dtype) != tf.string:
- raise ValueError('Regression input must be a single string Tensor; '
- 'got {}'.format(receiver_tensors))
+ raise ValueError(
+ 'Regression signatures can only accept a single tensor input of '
+ 'type tf.string. Please check to make sure that you have structured '
+ 'the serving_input_receiver_fn so that it creates a single string '
+ 'placeholder. If your model function expects multiple inputs, then '
+ 'use `tf.io.parse_example()` to parse the string into multiple '
+ f'tensors.\n Received: {receiver_tensors}')
return tf.compat.v1.saved_model.regression_signature_def(examples, self.value)
