Solved – How to set class weights for multi-class image segmentation

image processingneural networksweighted-data

I am trying to set class weights for a neural network with an imbalanced dataset.

Let's say I have the following values: I have 8000 images of class A, 1100 images of class B, 400 images of class C, and and 20 images of class D. Then how would I set class weights so that all classes are equally weighted?

My approach would be to do the following. If I wanted to find the class weight that I should assign to class A, then $$(\frac{A}{A+B+C+D})^{-1} = (\frac{8000}{8000+1100+400+20})^{-1}$$

Is this a good way to do it? Essentially I'm taking the reciprocal of the ratio.

Best Answer

An easy way to do this would be to simply assign weights so that they upweighted classes all have equal weight to the unweighted largest class. So in your case you would assign a weight of A/B to B, A/C to C, A/D to D and not weight A at all.

Related Question