Prettier printing for no-matching-signature errors in loaded SavedModels

Example (from the unit test):

ValueError: Could not find matching function to call loaded from the SavedModel. Got:
  Positional arguments (2 total):
    * [7, ({'a': <tf.Tensor 'x:0' shape=() dtype=int32>}, <tf.Tensor 'x_1:0' shape=() dtype=int32>)]
    * True
  Keyword arguments: {}

Expected these arguments to match one of the following 1 option(s):

Option 1:
  Positional arguments (2 total):
    * [6, ({u'a': TensorSpec(shape=(), dtype=tf.int32, name=u'x/1/0/a')}, TensorSpec(shape=(), dtype=tf.int32, name=u'x/1/1'))]
    * True
  Keyword arguments: {}

PiperOrigin-RevId: 247948754
This commit is contained in:
Allen Lavoie 2019-05-13 09:22:15 -07:00 committed by TensorFlower Gardener
parent 0666c6cf53
commit 0f379ec01f

View File

@ -234,14 +234,26 @@ def recreate_function(saved_function, concrete_functions):
if _concrete_function_callable_with(function, inputs, allow_conversion):
return _call_concrete_function(function, inputs)
available_signatures = [
concrete_functions[function_name].graph.structured_input_signature
for function_name in saved_function.concrete_functions
]
signature_descriptions = []
def _pretty_format_positional(positional):
return "Positional arguments ({} total):\n * {}".format(
len(positional),
"\n * ".join([str(a) for a in positional]))
for index, function_name in enumerate(saved_function.concrete_functions):
concrete_function = concrete_functions[function_name]
positional, keyword = concrete_function.structured_input_signature
signature_descriptions.append(
"Option {}:\n {}\n Keyword arguments: {}"
.format(index + 1, _pretty_format_positional(positional), keyword))
raise ValueError(
"Could not find matching function to call for inputs %r. "
"Only existing signatures are %r."
% (inputs, available_signatures))
"Could not find matching function to call loaded from the SavedModel. "
"Got:\n {}\n Keyword arguments: {}\n\nExpected "
"these arguments to match one of the following {} option(s):\n\n{}"
.format(_pretty_format_positional(args), kwargs,
len(saved_function.concrete_functions),
"\n\n".join(signature_descriptions)))
concrete_function_objects = []
for concrete_function_name in saved_function.concrete_functions: