Comments (9)
Hi @chriscarollo -
Thanks for reporting the issue. I have tested the code snippet and reproduces the reported behaviour. Attached gist file for reference.
We will look into the issue and update you the same.
from keras.
If your output is a dict, then the outputs are named by the key in the dict. This is the way you can control the names of the outputs even if you have a single output. So if you prefer, just add a layer to your model that wraps the output in a dict.
In all other cases (single output, list, tuple) the outputs are numbered and called output_<n>
.
model.export()
works like this with both Keras 2 and Keras 3. Now, it looks like tf.saved_model.save
works differently.
from keras.
Trivially reproduced:
input = keras.layers.Input( (1,), name='input_1' )
output = keras.layers.Dense( 8, name='output_1' )( input )
m = keras.Model( inputs=[input], outputs=[output], name='model_1' )
m.compile()
m.summary()
Model: "model_1"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type) ┃ Output Shape ┃ Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ input_1 (InputLayer) │ (None, 1) │ 0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ output_1 (Dense) │ (None, 8) │ 16 │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
Total params: 16 (64.00 B)
Trainable params: 16 (64.00 B)
Non-trainable params: 0 (0.00 B)
>>> m.export( 'test' )
INFO:tensorflow:Assets written to: test/assets
INFO:tensorflow:Assets written to: test/assets
Saved artifact at 'test'. The following endpoints are available:
* Endpoint 'serve'
args_0 (POSITIONAL_ONLY): TensorSpec(shape=(None, 1), dtype=tf.float32, name='input_1')
Output Type:
TensorSpec(shape=(None, 8), dtype=tf.float32, name=None)
Captures:
140410840896736: TensorSpec(shape=(), dtype=tf.resource, name=None)
140410840896912: TensorSpec(shape=(), dtype=tf.resource, name=None)
from keras.
FWIW I'm running Tensorflow 2.16.1 with Keras 3.3.3, but it does seem like this repros with Tensorflow 2.15 as well.
from keras.
Would you mind taking a look @hertschuh? CC: @nkovela1
from keras.
Hi @chriscarollo ,
Thanks for the report. I'm not really clear about what Triton needs from the saved model, but the outputs appear to have a name (more on that below).
but when I model.export() it says:
Output Type:
TensorSpec(shape=(None, 1), dtype=tf.float32, name=None)
Apparently, the only thing that is relevant in this message is the "output type". Unfortunately (and I don't know why) the name is missing.
If I also save as a .keras file, it correctly saves that layer with my "output_1" name.
Correct. Layers and outputs are very different concepts though. Do you need the layer? Or do you care about the output?
It appears that the output is named. It's just numbered starting from zero to support multiple outputs. So in your case, the output is named output_0
(independent of the layer name).
Here's how you can find out by adding this to your code above:
# Reload the model
loaded = tf.saved_model.load('test')
print("Outputs", loaded.signatures['serve'].structured_outputs.items())
Which prints
Outputs dict_items([('output_0', TensorSpec(shape=(None, 8), dtype=tf.float32, name='output_0'))])
But overall, I'm surprised Triton needs more than the name of the function, which is serve
by default.
from keras.
It's true that the outputs are showing up to Triton as output_N (with N starting at 0), but there are places where I was previously specifying a name on my output by naming the Dense layer(s) that were listed in the outputs parameter of the Model constructor, and using matching names in the output portion of Triton's config.pbtxt file. For example:
output [ { name: "output_win_prob" data_type: TYPE_FP32 dims: [ 1 ] } ]
It was definitely useful to be able to name outputs using the name of their output layer -- it's nice to be confident about what output you're talking about by using a unique name rather than just "the third output" -- and it doesn't seem like that's the case anymore.
from keras.
Oh! I didn't realize that outputs could take a dict, and the keys would become output names. Just tested it with Keras 3 and it works great -- Triton is happily loading my newly-trained model with all the output names it's expecting. Thanks!
from keras.
Are you satisfied with the resolution of your issue?
Yes
No
from keras.
Related Issues (20)
- keras-nightly: cannot import name '_tf_keras' from 'keras.api' HOT 4
- Error while exporting from keras format to TF SavedModel format, tf 2.16.1 and keras 3.3.3 HOT 3
- Keras 3 error with keras.ops.tile
- Why does the sequence length of vectors affect the calculation results of dense under bf16? HOT 2
- Are `ops.shape` vs `KerasTensor.shape` equivalent for most purposes? HOT 3
- [Help] Where is the trace/history of operations that led to a KerasTensor stored? HOT 2
- Should these 2 networks produce a different plot ? (to my eye, they are the same network.) HOT 8
- loss/losses are omitted from get_config/serialization
- Couldn't found `keras.backend` module in keras-nightly HOT 1
- having error in executing object detection module HOT 1
- Keras 3 gives incorrect output from evaluate/fit in distributed context HOT 4
- ValueError: Only instances of keras.Layer can be added to a Sequential model. Received: <tensorflow_probability.python.layers.dense_variational_v2.DenseVariational object at 0x000001C67AF5B4D0> (of type <class 'tensorflow_probability.python.layers.dense_variational_v2.DenseVariational'>) HOT 3
- `Sequential`-model for data augmentation within `tf.data.Dataset` with JAX backend not working HOT 1
- Load a model saved using keras 2.3.1 in keras 3 (containing bidirectionnal LSTM) HOT 5
- The saved keras model cannot be loaded. HOT 6
- Conv1D on custom shaped data HOT 1
- Adding `ops.associative_scan`? HOT 2
- Cant predict after training on TPU. HOT 2
- No file or directory found at spiral_keras_model.h5 HOT 1
- Memory leak when using custom DataGenerator HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras.