question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

converter drops model output keys

See original GitHub issue

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): No

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux 1e50325cd6ff 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 GNU/Linux This is a docker image using the attached Dockerfile

  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: N/A

  • TensorFlow.js installed from (npm or script link): pip – see attached Dockerfile

  • TensorFlow.js version (use command below): 3.7.0 – see attached Dockerfile

  • Browser version: N/A

  • Tensorflow.js Converter Version: 3.7.0

Describe the current behavior I have a model with five outputs, built using the functional API of tf.keras. The saved_model_cli signature looks like this:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['main'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 52, 14)
        name: serving_default_main:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['carlMoon'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 52)
        name: StatefulPartitionedCall:0
    outputs['hearts'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 52)
        name: StatefulPartitionedCall:1
    ...

Note the keys 'carlMoon' and 'hearts' in the two outputs shown.

I ran the tensorflowjs_converter to convert this model using this command line (from within the Docker container built with the attached Dockerfile):

tensorflowjs_converter --input_format tf_saved_model --output_format tfjs_graph_model --signature_name serving_default /data/e1431.4M.model /data/e1431.tfjs.model

The resulting model.json (pretty-printed with the attached json-pretty.mjs script which uses util.inspect() – valid JSON would require quoted strings for the keys) produces this output for the model signature:

  signature: {
    inputs: {
      main: {
        name: 'main:0',
        dtype: 'DT_FLOAT',
        tensorShape: { dim: [ { size: '-1' }, { size: '52' }, { size: '14' } ] }
      }
    },
    outputs: {
      'Identity_4:0': {
        name: 'Identity_4:0',
        dtype: 'DT_FLOAT',
        tensorShape: { dim: [ { size: '-1' }, { size: '52' } ] }
      },
      'Identity_1:0': {
        name: 'Identity_1:0',
        dtype: 'DT_FLOAT',
        tensorShape: { dim: [ { size: '-1' }, { size: '52' } ] }
      },
     ....

Note that the output keys have become Identity_4:0 and Identity_1:0 instead of the original keys carlMoon and hearts.

Describe the expected behavior

The model.json signature outputs section should preserve the original keys and look like this:

    outputs: {
      carlMoon: {
        name: 'Identity_4:0',
        dtype: 'DT_FLOAT',
        tensorShape: { dim: [ { size: '-1' }, { size: '52' } ] }
      },
      hearts: {
        name: 'Identity_1:0',
        dtype: 'DT_FLOAT',
        tensorShape: { dim: [ { size: '-1' }, { size: '52' } ] }
      },
      ...

Standalone code to reproduce the issue N/A

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

The Dockerfile and the source model are attached in one tar ball.

bugfiles.tar.gz

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
pyu10055commented, Jun 7, 2021

@jimlloyd models with multiple outputs can have a proper mapped signatures, as you have discovered, only when outputs have different data types or shapes. TFJS relies on TensorFlow internal code to inline the StatefulPartitionedCall function, which will map nodes for the input/output of the function to different names.

0reactions
google-ml-butler[bot]commented, Jul 3, 2021

Are you satisfied with the resolution of your issue? Yes No

Read more comments on GitHub >

github_iconTop Results From Across the Web

Models - Hugging Face
Here is how it works: save which state_dict keys we have; drop state_dict before the model is created, since the latter takes 1x...
Read more >
After converting the model to .tflite and running it on Android ...
Hello everyone! This is my first neural network, so there are often problems. And now there is a problem that I can't solve....
Read more >
Common Mistakes in DC/DC Converters and How to Fix Them
The output voltage measurement shows the converter's response to a large load step increase. As expected, the output voltage initially drops but quickly ......
Read more >
Convert a Tensorflow2 model to OpenVINO® | by Filippo Valle
OpenVINO is a powerful tool, but it requires some passages in order to work properly. We will go trough the process of converting...
Read more >
How to Save and Load Your Keras Deep Learning Model
In this post, you will discover how to save your Keras models to files and load them up ... split into input (X)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found