I have 2 classes (1 representing positive class and 0 representing negative class). I calculate weights for my BCE loss as follows.
Weights for Zero = 1 / (number of zeros in the entire dataset)
Weights for ones = 1 / (number of ones in the entire dataset)
but the problem is that the weights of zeros and ones becomes very small like 1e-6 and 1e-4 respectively.
I further change it to
Weights for Zero = 1 - (number of zeros in the entire dataset / total number of pixels in the dataset)
Weights for ones = 1 - (number of ones in the entire dataset / total number of pixels in the dataset)
By this way i can get the weights in range [0-1] with zeros getting close to zero and ones getting close to 1.
I would like to know if this is the correct way to do or is there any suggested way? I saw many reference discussions but they focus on classification and not segmenting pixels.
Do we need to give larger weight to zero class which has more occurrence in the mask ? or the other way round ? because in this reference it says we to need to give more weights to classes which are less.