Skip to content

Commit 82a4f69

Browse files
Reorder keras outputs if possible (#1480)
Signed-off-by: Tom Wildenhain <[email protected]>
1 parent c8eec1e commit 82a4f69

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tf2onnx/convert.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ def from_keras(model, input_signature=None, opset=None, custom_ops=None, custom_
322322
initialized_tables = None
323323
tensors_to_rename = tensor_names_from_structed(concrete_func, input_names, output_names)
324324

325+
if model.output_names:
326+
# model.output_names is an optional field of Keras models indicating output order. It is None if unused.
327+
reverse_lookup = {v: k for k, v in tensors_to_rename.items()}
328+
output_names = [reverse_lookup[out] for out in model.output_names]
329+
325330
with tf.device("/cpu:0"):
326331
frozen_graph = tf_loader.from_function(concrete_func, input_names, output_names, large_model=large_model)
327332
model_proto, external_tensor_storage = _convert_common(

0 commit comments

Comments
 (0)