[go: nahoru, domu]

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

loss function input "y_pred" should be full list of model-outputs #46428

Open
leokster opened this issue Jan 14, 2021 · 2 comments
Open

loss function input "y_pred" should be full list of model-outputs #46428

leokster opened this issue Jan 14, 2021 · 2 comments
Assignees
Labels
comp:keras Keras related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:feature Feature requests

Comments

@leokster
Copy link

System information

  • TensorFlow version (you are using): 2.4
  • Are you willing to contribute it (Yes/No): Yes, but it seems that multiple other things might depend on it

Describe the feature and the current behavior/state.
In the current version of Keras, the loss function is applied for each output of the model elementwise (if there are multiple), or one can define for each individual output one loss function. This seems to be not really consistent with other fundamentals in Keras / TF, and it would be better to have at least the possibility to get the full list of model-outputs as a y_pred input of the loss function. It's especially confusing since in the train_step

loss = self.compiled_loss(
y, y_pred, sample_weight, regularization_losses=self.losses)

one passes the full list of model-outputs as y_pred, but the loss function is run multiple times for each individual model-output and hence gets every element of the list separately as y_pred

Will this change the current api? How?
Yes, there wouldn't be multiple losses for a model but only one. One could still get the same results by building a "wrapper" around the individual losses and adding it as a loss.

Who will benefit from this feature?
Everyone who wants to build more complex models, especially if you have different output dimensions in your model-output, where the proposed solution is in keras-team/keras#14140 would not work anymore (e.g., one output an image and one output a label).

Any Other info.

@manaspalaparthi
Copy link

this will also help while passing Input image (x_train) to loss function for image reconstruction loss. also in multi-task network and VAE

@manaspalaparthi
Copy link
manaspalaparthi commented Jan 20, 2021

A temporary solution is to name each layer before output,.

then use
`def loss_function(y_true, y_pred):
if y_pred.name = "output1 ":
XYZ
if y_pred.name = "output2":
ZYX

return loss `

however to combine these losses,. we might need to call multiple times in compile method

model.compile(optimizer= optimizer, loss={ 'output1' : loss_function , 'output2' : loss_function } , loss_weights = accordingly )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:keras Keras related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

4 participants