# How to set class weights for multi-class image segmentation?

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.