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

Difference between loss_weights and class_weights #10507

Closed
GGYIMAH1031 opened this issue Jun 22, 2018 · 3 comments
Closed

Difference between loss_weights and class_weights #10507

GGYIMAH1031 opened this issue Jun 22, 2018 · 3 comments

Comments

@GGYIMAH1031
Copy link

GGYIMAH1031 commented Jun 22, 2018

What is the difference between the loss_weights argument, found in the compile function (compile(self, optimizer, loss=None, metrics=None, loss_weights=None)) and the class_weight argument in the "fit" method (fit(self, x=None, y=None, batch_size=None, class_weight = None))?

@pavithrasv
Copy link
Contributor

loss_weights parameter on compile is used to define how much each of your model output loss contributes to the final loss value ie. it weighs the model output losses. You could have a model with 2 outputs where one is the primary output and the other auxiliary. eg. 1. * primary + 0.3 * auxiliary. The default values for loss weights is 1.

class_weight parameter on fit is used to weigh the importance of each sample based on the class they belong to, during training. This is typically used when you have an uneven distribution of samples per class.

@xaram
Copy link

xaram commented Apr 16, 2020

How do I use loss_weights parameter to weight each of the training examples differently while calculating the loss function?

@MingweiSamuel
Copy link

MingweiSamuel commented Apr 26, 2020

@xaram

How do I use loss_weights parameter to weight each of the training examples differently while calculating the loss function?

You don't, you use sample_weights https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit alongside the X and Y data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants