0

I am attempting to generate a set of weights to supply to a loss function for my neural network. This network attempts to categorize pixel values between a set of classes. This set of classes is unbalanced in the number of samples.

For example say I have the class labels and their respective counts:

class0 - 67
class1 - 18
class2 - 8
class3 - 4
class4 - 2
class5 - 1

To generate their relative weights I sum the total samples and divide each count by the sum and subtract that from 1.

class0 - 1.0 - 67/100 = 0.33
class1 - 1.0 - 18/100 = 0.82
class2 - 1.0 - 8/100  = 0.92
class3 - 1.0 - 4/100  = 0.96
class4 - 1.0 - 2/100  = 0.98
class5 - 1.0 - 1/100  = 0.99

Thus when calculating a loss each class' loss is equally weighted in the final value based on their abundance in the data set.

Though, I have found that I care much more about the much less abundant classes. So much so that I would like to "extremely" increase the ratio between the weights so that less abundant classes makeup a much larger part of the loss.

Is there a "nice and pretty" way to do this mathematically? I'm not necessarily asking if my method in terms of the problem described is correct, but just a way to change the relative ratio/scale between these weights. I would image there is a way to "map" these over, say, an exponential to achieve the desired result?

Technically the weights can be anything in the range [eps, float32.max] but I would like to keep them between [eps, 1.0].

KDecker
  • 861
  • 2
  • 11
  • 23

0 Answers0