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

Add BinarySemanticSegmentationTask to properly compute IoU #245

Open
calebrob6 opened this issue Nov 14, 2021 · 8 comments · May be fixed by #2219
Open

Add BinarySemanticSegmentationTask to properly compute IoU #245

calebrob6 opened this issue Nov 14, 2021 · 8 comments · May be fixed by #2219
Labels
trainers PyTorch Lightning trainers

Comments

@calebrob6
Copy link
Member

ETCI2021 is a binary segmentation task with a positive class and a background class. As such, the IoU metric should only be computed over the positive class (i.e. computing IoU), however currently the 2 class mIoU is computed.

@calebrob6 calebrob6 added the trainers PyTorch Lightning trainers label Nov 14, 2021
@adamjstewart adamjstewart added this to the 0.1.1 milestone Nov 20, 2021
@adamjstewart
Copy link
Collaborator

@calebrob6 I think you mentioned that you hacked this to get this working for the paper. What did that hack look like? We can create a BinarySemanticSegmentationTask that subclasses SemanticSegmentationTask and includes this hack.

@adamjstewart adamjstewart modified the milestones: 0.1.1, 0.1.2 Dec 19, 2021
@adamjstewart adamjstewart modified the milestones: 0.1.2, 0.2.1 Jan 1, 2022
@sofstef
Copy link

sofstef commented Mar 12, 2022

@adamjstewart @calebrob6 is this something you're still planning on adding? I'm having a go at creating a binary segmentation task and it would be helpful to know if you've already done something similar!

@adamjstewart
Copy link
Collaborator

I don't think either of us have worked on this yet, so if you get one working that would be great!

@adamjstewart adamjstewart modified the milestones: 0.2.1, 0.3.0 Mar 16, 2022
@adamjstewart adamjstewart changed the title SemanticSegmentationTask doesn't compute IoU correctly for binary segmentation tasks Add BinarySemanticSegmentationTask to properly compute IoU Mar 16, 2022
@remtav
Copy link
Contributor

remtav commented Apr 13, 2022

Another binary semantic segmentation scenario is a Spacenet-type dataset, where labels come in as (N, 1, W, H), not (N, 2, W, H), ie. no background class. It would be great if the BinarySemanticSegmentationTask covers this scenario, using the sigmoid() operation rather than argmax(dim=1), for example. Also, as a heads up for whoever develops this new task, torchmetrics seems to have a consistency issue for this use case. I've been performing tests with the Spacenet1 data and haven't been able to get IoU nor accuracy working yet with torchmetrics, even with some hacks.

@ashnair1
Copy link
Collaborator

ashnair1 commented Oct 4, 2022

The next release of torchmetrics (v0.10.0) will contain binary, multi-class and multi-label variants of all the classification metrics. An RC has already been released.

@isaaccorley
Copy link
Collaborator

isaaccorley commented Oct 4, 2022

Should we actually have a task for binary segmentation with sigmoid outputs where 0 presumably means background or should we force binary datasets to have a background class so everything can be multiclass for consistency. I guess I'm not seeing the benefit of having a separate task over keeping the datasets consistent?

@ashnair1
Copy link
Collaborator

ashnair1 commented Oct 6, 2022

Forcing binary datasets to have a background class would be the simpler option. I had trained a model on the Inria dataset in the same way (setting num_classes=2) and it worked as expected. We could go one step further and always handle background classes. This way users would just specify num_classes = N in yaml config instead of N + 1 for segmentation and object detection tasks.

If we were to separate it out into a new BinarySemanticSegmentation task we would need to:

  • Switch to binary metrics
  • Switch to binary losses (BCE instead of CE) or enable binary mode for losses (Jaccard(mode=binary))
  • Change the forward methods to provide sigmoid outputs.

@adamjstewart
Copy link
Collaborator

Given that torchmetrics is splitting binary and multi-class into separate metrics, I think it would make sense to have separate tasks. At the very least, there should be an option in SemanticSegmentationTask that allows you to select between binary and multi-class.

@adamjstewart adamjstewart removed this from the 0.4.0 milestone Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
trainers PyTorch Lightning trainers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants