Found unexpected keys that do not correspond to any Model output: (param1). Expected: (param1)
Package:
keras
52268

Exception Class:
ValueError
Raise code
not any(tf.nest.is_nested(y_p) for y_p in y_pred))
if (single_output or outputs_are_flat_list) and isinstance(struct, dict):
output_names = output_names or create_pseudo_output_names(y_pred)
struct = copy.copy(struct)
new_struct = [struct.pop(name, None) for name in output_names]
if struct:
raise ValueError('Found unexpected keys that do not correspond '
'to any Model output: {}. Expected: {}'.format(
struct.keys(), output_names))
if len(new_struct) == 1:
return new_struct[0]
return new_struct
else:
return struct
def
Links to the raise (1)
https://github.com/keras-team/keras/blob/4a978914d2298db2c79baa4012af5ceff4a4e203/keras/engine/compile_utils.py#L649See also in the other packages (1)
(❌️ No answer)
tensorflow/found-unexpected-keys-that-do
Ways to fix
Summary:
This exception can arise when calling the map_to_output_names function. This function takes in 3 parameters: y_pred, output_names, and struct. y_pred is a list of values. output_names is a list of names as strings. struct is a dictionary. The important thing to keep in mind is that the keys of the struct must match the output_names. If they are different from each other you will get this exception. It is important not to reverse the order of the keys and values in the dictionary. The keys must be the output_names, not the values.
Code to Reproduce the Error (Wrong):
from keras.engine.compile_utils import map_to_output_names
y_pred = [1,2,3,4,5]
output_names = ['a', 'b', 'c', 'd', 'e']
struct = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e'}
map_to_output_names(y_pred, output_names, struct)
Error Message:
ValueError Traceback (most recent call last)
<ipython-input-68-38522024d135> in <module>()
4 output_names = ['a', 'b', 'c', 'd', 'e']
5 struct = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e'}
----> 6 map_to_output_names(y_pred, output_names, struct)
/usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py in map_to_output_names(y_pred, output_names, struct)
649 raise ValueError('Found unexpected keys that do not correspond '
650 'to any Model output: {}. Expected: {}'.format(
--> 651 struct.keys(), output_names))
652 if len(new_struct) == 1:
653 return new_struct[0]
ValueError: Found unexpected keys that do not correspond to any Model output: dict_keys([1, 2, 3, 4, 5]). Expected: ['a', 'b', 'c', 'd', 'e']
Working Version (Right):
from keras.engine.compile_utils import map_to_output_names
y_pred = [1,2,3,4,5]
output_names = ['a', 'b', 'c', 'd', 'e']
# keys and values have been swapped
updated_struct = {'a': 1, 'b': 2, 'c': 3, 'd': 4,'e': 5}
map_to_output_names(y_pred, output_names, updated_struct)
Add a possible fix
Please authorize to post fix