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:
parent
0666c6cf53
commit
0f379ec01f
@ -234,14 +234,26 @@ def recreate_function(saved_function, concrete_functions):
|
|||||||
if _concrete_function_callable_with(function, inputs, allow_conversion):
|
if _concrete_function_callable_with(function, inputs, allow_conversion):
|
||||||
return _call_concrete_function(function, inputs)
|
return _call_concrete_function(function, inputs)
|
||||||
|
|
||||||
available_signatures = [
|
signature_descriptions = []
|
||||||
concrete_functions[function_name].graph.structured_input_signature
|
|
||||||
for function_name in saved_function.concrete_functions
|
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(
|
raise ValueError(
|
||||||
"Could not find matching function to call for inputs %r. "
|
"Could not find matching function to call loaded from the SavedModel. "
|
||||||
"Only existing signatures are %r."
|
"Got:\n {}\n Keyword arguments: {}\n\nExpected "
|
||||||
% (inputs, available_signatures))
|
"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 = []
|
concrete_function_objects = []
|
||||||
for concrete_function_name in saved_function.concrete_functions:
|
for concrete_function_name in saved_function.concrete_functions:
|
||||||
|
Loading…
Reference in New Issue
Block a user