Class weights in custom training loop

I know that model.fit() has an extra parameter called class_weights that helps when working with imbalanced data. Can anyone help me with how to implement this functionality when using a custom training loop. Thanks in advance.

2 Likes

you can write your own loss function. in that loss function call BinaryCrossentropy and then multiply the result in the weight you want and return that.

2 Likes

Right why didn’t I think of that. Thanks for pointing me in the right direction.