converter drops model output keys
See original GitHub issuePlease 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top GitHub Comments
@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.
Are you satisfied with the resolution of your issue? Yes No