-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Issue to set metrics with multiple outputs Model #21259
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
Comments
Hi @RPlumey-asulab, thanks for reporting this. If you try naming the outputs layers with the |
Hi, Just to make sure I understand — is it normal that the model throws an error unless the output layers are explicitly named to match the keys used in the outputs dict? a = Input(shape=(3,5), name='a')
x,y,z = Split(axis=-2, num_or_size_splits=3)(a)
stuff= Stuff(...)
x = stuff(x)
y = stuff(y)
z = stuff(z)
model = Model(inputs={'a': a}, outputs={'x': x, 'y': y, 'z': z}) Thanks for the quick reply. |
Hi @RPlumey-asulab, If you don't name the layers, Keras would implicitly assign names to them, and you’d need to use those auto-generated names (e.g., 'dense', 'dense_1', etc.) in your loss or metrics dictionaries. |
Got it, but. Just to be sure — in the second case, let’s say I have a Dense layer named "Dense" and it's the output layer (e.g., Thanks again! |
Hi @RPlumey-asulab, for multiple named outputs
for single output layer
|
Hi @dhantule , So, with the following code: import keras
from keras import Input, Model
from keras.layers import Dense, Layer
import tensorflow as tf
import numpy as np
input_ = Input(shape=(3,5), name='input')
class SplitLayer(Layer):
def call(self, inputs):
return [ tf.squeeze(t, axis=1)
for t in tf.split(inputs, num_or_size_splits=inputs.shape[1], axis=1)
]
x, y, z = SplitLayer(name='split')(input_)
dense = Dense(3, activation='relu', name='dense')
x = dense(x)
y = dense(y)
z = dense(z)
model = keras.Model(inputs=input_, outputs={'x': x, 'y': y, 'z': z})
model.compile(
optimizer='adam',
loss={'x': 'mse', 'y': 'mse', 'z': 'mse'},
metrics={'x': ['mae'], 'y': ['mae'], 'z': ['mae']}
)
model.summary()
model.fit(
np.random.rand(100, 3, 5),
{'x': np.random.rand(100, 3), 'y': np.random.rand(100, 3), 'z': np.random.rand(100, 3)},
epochs=10
) I'm getting this error:
Is this behavior unexpected, or am I doing something wrong here? Thanks a lot! Best, |
Hi,
I’m using the following setup:
But I’m getting this error:
ValueError: In the dict argument 'metrics', key 'b' does not correspond to any model output.
Do you know why the model doesn’t recognize 'b' and 'c' as valid output names even though I used them in the outputs dictionary?
Also, when I try using this instead:
I get another error:
ValueError: For a model with multiple outputs, when providing the 'metrics' argument as a list, it should have as many entries as the model has outputs. Received: metrics=[['accuracy'], ['accuracy']] of length 2 whereas the model has 0 outputs.
Any idea what’s going on here?
The text was updated successfully, but these errors were encountered: