keras
keras copied to clipboard
Use outputs dictionary keys as output_names if provided
This PR is meant to resolve issue #16405.
This implementation is the first solution mentioned in https://github.com/keras-team/keras/issues/16405#issuecomment-1102255538. You are still invited to discuss other solutions.
The implementation relies on the behavior of tf.nest.flatten when model._output_layers are created. Particularly, on the ordering, which is the sorted order of the dictionary keys. An alternative might be to search each layer from model._output_layers in the nested structure and then select its name. That strategy seems more complicated but would be independent of the way how model._output_layers is created.
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
For more information, open the CLA check for this pull request.
We can't change the behavior on this. This is potentially confusing though, so a warning would be great!
Thanks for the PR. Yes, so it would be inconsistent to use Input.name as the input name for every situation (list of Inputs, tuples of inputs...) except the dict case. We should always use Input.name, even in the dict case.
Now, it's certainly true that if you use dict keys that differ from Input.name, then "what is the name of my input?" becomes an ambiguous question. Users should make sure to use consistent input names and dict keys in order to avoid any confusion. Let's simply add a warning in case of mismatch.
I thought the purpose of passing dicts is to overwrite the names. So if I pass a dict with different keys than layer names, the data dictionary I pass to fit or predict use that keys. If I pass a list or tuple the data dict keys are the layer names. So that is just the same "inconsistency", I guess. Problems also appear when I nest multi output models. Then I do not know which output comes from which layer inside the nested models. (see the code examples in the issue)
If you keep two sets of names to refer to the same objects, that's on you. The framework cannot read your mind to determine which set you intended to use. Hence why it would be helpful to introduce a warning to force the user to keep a single consistent set of names to refer to Input objects.
@szleb Any update on this PR? Please. Thank you!
@szleb Any update on this PR? Please. Thank you!
Hi @szleb Any update on this PR? Please. Thank you!
Hi @szleb I'm going to go ahead and close this PR, because it seems to have stalled. If you're still interested in pursing this (and responding to my comments), please feel free to reopen! Thank you!