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

Training using Bisenetv2 with custom dataset of 2 classes #1430

Closed
JJLimmm opened this issue Mar 29, 2022 · 13 comments
Closed

Training using Bisenetv2 with custom dataset of 2 classes #1430

JJLimmm opened this issue Mar 29, 2022 · 13 comments
Assignees

Comments

@JJLimmm
Copy link

JJLimmm commented Mar 29, 2022

Hi, if i want to train a model using the bisenetv2 model, and a custom dataset where the classes are either water puddles or background, which files should i be making changes in to ensure that i only want the waterpuddles class to be predicted?

Model: Bisenetv2
Dataset: Custom dataset (ChaseDB1 format)

  • Annotation masks only includes 0 and 1; 0 for background, 1 for water puddles.

Currently, i have made the following changes...

1: Under configs/base/models/bisenetv2.py, i have changed the number of classes to 2

2: I have created a custom dataset class called waterpuddlesDataset(), and added into the mmseg/datasets/waterpuddles.py directory. In that file, the classes is defined as ('background', 'waterpuddle').

Another question is, how does the reduce_zero_label work?

When i set it to True, my validation accuracy for waterpuddle class become NaN.

@MeowZheng
Copy link
Collaborator

My suggestion is to use BCELoss and set the channel of the output as one.

@JJLimmm
Copy link
Author

JJLimmm commented Mar 31, 2022

My suggestion is to use BCELoss and set the channel of the output as one.

Sorry, for setting the channel of the output as one, which part of it are you referring to in the base model config file configs/base/models/bisenetv2.py? @MeowZheng

@MeowZheng
Copy link
Collaborator

num_classes of decode_head

@JJLimmm
Copy link
Author

JJLimmm commented Mar 31, 2022

num_classes of decode_head

I changed the channel of the output to 1 and using BCE Loss by setting CrossEntropyLoss's use_sigmoid=True, as you advised @MeowZheng . But i get this error shown below

error_ss

Below are the config files i used for this run.
Under configs/*

Under mmseg/datasets/*

@MeowZheng
Copy link
Collaborator

please fetch the master branch, we have fix the bug

@JJLimmm
Copy link
Author

JJLimmm commented Mar 31, 2022

Hi @MeowZheng and @RockeyCoss , i am still getting an error after fetching the new fixes.

image

Configs used are still the same as the previous replies above other than settting avg_non_ignore = True, and ignore_index=None in decode_head.

@RockeyCoss
Copy link
Contributor

RockeyCoss commented Mar 31, 2022

Hi @JJLimmm There are some problems with our BCELoss currently. You can try setting num_class=2 and ·use_sigmoid=False .

@JJLimmm
Copy link
Author

JJLimmm commented Apr 1, 2022

Hi @JJLimmm There are some problems with our BCELoss currently. You can try setting num_class=2 and ·use_sigmoid=False .

Alright noted @RockeyCoss ! However, for Binary class loss, shouldnt it only be 1 class?

And if i were to set num_class=2 , do i have to set anything else like shown below

  • setting ignore_index=None in decode_head?
  • setting avg_non_ignore=True?
  • for reduce_zero_label in custom dataset?

@JJLimmm
Copy link
Author

JJLimmm commented Apr 1, 2022

@RockeyCoss Right now, i have set the following configs and run training once...

  • CLASSES = ('background', 'waterpuddles')
  • reduce_zero_label=True
  • In decode_head and auxiliary heads for Bisenetv2,
  • num_classes=2
  • use_sigmoid=False
  • use_mask=False
  • avg_non_ignore=True

And during validation in training run, i got the following output.

image

The waterpuddles class is 0 for IoU.

@RockeyCoss
Copy link
Contributor

RockeyCoss commented Apr 1, 2022

@JJLimmm Well, if you set reduce_zero_label=True, then the class corresponds to 0 in the label, background in this case, should not appear in the CLASSES tuple. In this 2-class-segmentation problem, setting reduce_zero_label=True is equivalent to ignoring all the background pixels, which is not recommended. Because by doing so, your model can only see the pixels of class waterpuddles during training. In other words, the model is merely trained on positive samples, which may affect its performance when inferencing an image with no pixels belonging to class waterpuddles. (In fact, if you set reduce_zero_label=True, then the easiest way for the model to reduce loss is to predict all the pixels in the image as waterpuddles)

As to avg_non_ignore, it means that the loss is only averaged over non-ignored targets. I recommend setting it True since it's more reasonable. Reduce_zero_label defaults to 255, so you don't need to set it as None.

In summary, here are the settings I recommend:

  • CLASSES = ('background', 'waterpuddles')
  • reduce_zero_label=False
  • In decode_head and auxiliary heads for Bisenetv2,
  • num_classes=2
  • use_sigmoid=False
  • use_mask=False
  • avg_non_ignore=True

@RockeyCoss
Copy link
Contributor

Alright noted @RockeyCoss ! However, for Binary class loss, shouldnt it only be 1 class?

Yes, you are right. However, there is a problem with our BCELoss currently. We will fix it as soon as possible. Setting num_classes=2 and use_sigmoid=False is basically the same.

@JJLimmm
Copy link
Author

JJLimmm commented Apr 4, 2022

Alright noted @RockeyCoss ! However, for Binary class loss, shouldnt it only be 1 class?

Yes, you are right. However, there is a problem with our BCELoss currently. We will fix it as soon as possible. Setting num_classes=2 and use_sigmoid=False is basically the same.

Alright noted, thanks for the help and will await the bug fix for this!

@MeowZheng
Copy link
Collaborator

MeowZheng commented Apr 21, 2022

we have fixed it in #1454

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

No branches or pull requests

3 participants