Skip to content
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

[Feature Request] Re-enable multi-output logs #19219

Closed
innat opened this issue Feb 23, 2024 · 4 comments · Fixed by #20023
Closed

[Feature Request] Re-enable multi-output logs #19219

innat opened this issue Feb 23, 2024 · 4 comments · Fixed by #20023
Assignees
Labels
stat:awaiting keras-eng Awaiting response from Keras engineer type:feature The user is asking for a new feature.

Comments

@innat
Copy link

innat commented Feb 23, 2024

If a model is configured for multi-output, in keras 2, we can get the log message for all corresponding outputs. But in keras 3, it is removed and only shows the summarized log message. Unlike mult-class classification, returning log message for mult-output sounds more natural.

priority_pred = layers.Dense(1, name="priority")(x)
department_pred = layers.Dense(num_departments, name="department")(x)

model = keras.Model(
    inputs=[title_input, body_input, tags_input],
    outputs={"priority": priority_pred, "department": department_pred},
)

model.compile(
    optimizer=keras.optimizers.RMSprop(1e-3),
    loss={
        "priority": keras.losses.BinaryCrossentropy(from_logits=True),
        "department": keras.losses.CategoricalCrossentropy(from_logits=True),
    },
    loss_weights={"priority": 1.0, "department": 0.2},
)

model.fit

in keras 2

Epoch 1/2
 40/401s 12ms/step - loss: ?, priority_loss: ?, department_loss: ?

in keras 3

Epoch 1/2
 40/401s 12ms/step - loss: ?

Posted as a bug #19159, but it turned out that it was intentionally removed.

@james77777778
Copy link
Contributor

+1 for this

I have also filed the issue at #18993

@sachinprasadhs sachinprasadhs added type:feature The user is asking for a new feature. stat:awaiting keras-eng Awaiting response from Keras engineer labels Feb 26, 2024
@arthurflor23
Copy link

I'm having the same restriction using GAN models, which have several loss values...

@fchollet
Copy link
Collaborator

fchollet commented Apr 2, 2024

The recommendation is to pass metrics= with a dict mapping different outputs to the metric you want to monitor. If the metric you need is the same as the loss, pass that. e.g.

model.compile(
    optimizer=keras.optimizers.RMSprop(1e-3),
    loss={
        "priority": keras.losses.BinaryCrossentropy(from_logits=True),
        "department": keras.losses.CategoricalCrossentropy(from_logits=True),
    },
    metrics={
        "priority": [keras.metrics.BinaryCrossentropy(from_logits=True)],
        "department": [keras.metrics.CategoricalCrossentropy(from_logits=True)],
    },
    loss_weights={"priority": 1.0, "department": 0.2},
)

@fchollet fchollet closed this as completed Apr 2, 2024
@innat
Copy link
Author

innat commented Apr 2, 2024

@fchollet
Just to be clear, in keras 2, we can get

Epoch 1/2
 40/401s 12ms/step - loss: ?, priority_loss: ?, department_loss: ?

but in keras 3

Epoch 1/2
 40/401s 12ms/step - loss: ?

So, it's not about the metrics but loss scores of a multi output model. And it seems missing in the log in keras 3. We found this unexpected, coz sometimes we prefer to monitor target loss score using callback to reduce lr or saving checkpoint, etc. As this ticket is closed, I guess this is fixed but I've just tried a sample code with keras-nightly (3.2.0.dev2024040203), it's same as before.

model.compile(
    optimizer=keras.optimizers.RMSprop(1e-3),
    loss={
        "priority": keras.losses.BinaryCrossentropy(from_logits=True),
        "department": keras.losses.CategoricalCrossentropy(from_logits=True),
    },
    loss_weights={"priority": 0.1, "department": 0.2},
)

Epoch 1/2
40/40 ━━━━━━━━━━━━━━━━━━━━ 5s 48ms/step - loss: 0.6244
Epoch 2/2
40/40 ━━━━━━━━━━━━━━━━━━━━ 2s 44ms/step - loss: 0.6285

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting keras-eng Awaiting response from Keras engineer type:feature The user is asking for a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants