0
$\begingroup$

I am creating a neural network using TensorFlow (v2.9.2) for an imbalanced image dataset. While doing so, I noticed that model.compile() method has an argument loss_weights, and model.fit() has an argument class_weight. I know that the loss_weights argument would transform the loss function to a weighted one and propagate the loss proportionately. But I am confused about the class_weight argument.

My questions:

1. In what way do they differ from each other, specifically in terms of affecting the training process?

2. Should the value of class_weight argument be the same as loss_weights argument, considering that the distribution ratios among the categories remain the same throughout the process?

$\endgroup$

1 Answer 1

0
$\begingroup$

loss_weight is more related to having two loss functions when having two outputs from your model, but class_weight is more related to your data since you have imbalanced dataset.

Please check model.compile() documentation.

So it is not necessary that the values of these arguments be the same.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.