Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder keras outputs if possible #1480

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tf2onnx/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ def from_keras(model, input_signature=None, opset=None, custom_ops=None, custom_
initialized_tables = None
tensors_to_rename = tensor_names_from_structed(concrete_func, input_names, output_names)

if model.output_names:
# model.output_names is an optional field of Keras models indicating output order. It is None if unused.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly for the huggingface models this is None. But on some other models it is present.

reverse_lookup = {v: k for k, v in tensors_to_rename.items()}
output_names = [reverse_lookup[out] for out in model.output_names]

with tf.device("/cpu:0"):
frozen_graph = tf_loader.from_function(concrete_func, input_names, output_names, large_model=large_model)
model_proto, external_tensor_storage = _convert_common(
Expand Down