Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How was the class weights were defined #11

Open
Guolin-Yin opened this issue Jul 15, 2024 · 1 comment
Open

How was the class weights were defined #11

Guolin-Yin opened this issue Jul 15, 2024 · 1 comment

Comments

@Guolin-Yin
Copy link

Dear authors,

Thanks for your amazing work, it helps me a lot.

However, I am wondering how the class weight was defined (quoted). I guess it could be related to the number of samples for each class in the dataset, but I am not sure. Please give me some hints on how it is computed.

CLASS_WEIGHTS = {

@buffalotheory
Copy link

Hello,

I've been looking into this as well, but am not officially involved with the project.

The weights are calculated with the following block of code in compute_class_weights.py

  all_counts = sum(list(class_pixel_counts.values()))
  n_classes = len(class_pixel_counts)
  class_weights = {k: all_counts / (n_classes * v) for k, v in class_pixel_counts.items()}

all_counts / n_classes yeilds the average number of counts per class.

Each class weight is then the average_count_per_class / count_per_class

This means that:

  1. The values will vary from zero to positive infinity
  2. The weight for each class is inversely-proportional to number of pixels for that class
  3. If a class contains exactly the average number of pixels, then it's weight will be 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants