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

SemanticSegmentationTrainer: ignore_zeros -> ignore_index #644

Merged
merged 11 commits into from
Jul 2, 2022

Conversation

calebrob6
Copy link
Member

Fixes #444

@github-actions github-actions bot added the trainers PyTorch Lightning trainers label Jul 2, 2022
@adamjstewart
Copy link
Collaborator

Is there any reason not to rename ignore_zeros to ignore_index in the __init__ parameter list?

@calebrob6
Copy link
Member Author

We don't need to ignore other values and old segmentation trainer checkpoints will not be easily loadable

@github-actions github-actions bot added the testing Continuous integration testing label Jul 2, 2022
@@ -11,7 +11,7 @@ experiment:
in_channels: 26
num_classes: 2
num_filters: 1
ignore_zeros: True
ignore_zeros: False
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't ignore_zeros with two classes, this causes the Accuracy metric to break

@@ -97,7 +97,7 @@ def model_kwargs(self) -> Dict[Any, Any]:
"encoder_name": "resnet18",
"encoder_weights": None,
"in_channels": 1,
"num_classes": 1,
"num_classes": 2,
Copy link
Member Author

@calebrob6 calebrob6 Jul 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instantiating the torchmetrics classes with a single class doesn't make sense

self.ignore_zeros = None if kwargs["ignore_zeros"] else 0
if not isinstance(kwargs["ignore_zeros"], bool):
raise ValueError("ignore_zeros must be a bool")
if kwargs["ignore_zeros"] and kwargs["loss"] == "jaccard":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically warn about this because a user might expect training with jaccard to behave similarly to training with ce or focal loss, however it doesn't

@adamjstewart
Copy link
Collaborator

We don't need to ignore other values

We don't need to ignore other values yet. Presumably this feature exists in torchmetrics because some datasets use a class other than 0 for background. This will break as soon as someone adds a dataset with a different index that needs to be ignored.

old segmentation trainer checkpoints will not be easily loadable

I'm concerned about reproducibility of experiments, but not necessarily reproducibility with older versions of TorchGeo. We are still in alpha mode and backwards incompatible changes like this would be better sooner rather than later. I still say we should switch to ignore_index to match torchmetrics.

@calebrob6
Copy link
Member Author

Okay fair enough! Any thoughts on the warning?

conf/chesapeake_cvpr.yaml Outdated Show resolved Hide resolved
torchgeo/trainers/segmentation.py Outdated Show resolved Hide resolved
torchgeo/trainers/segmentation.py Outdated Show resolved Hide resolved
calebrob6 and others added 3 commits July 2, 2022 10:26
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
@adamjstewart adamjstewart changed the title Clarify the ignore_zeros parameter to the segmentation trainer SemanticSegmentationTrainer: ignore_zeros -> ignore_index Jul 2, 2022
@adamjstewart adamjstewart added this to the 0.3.0 milestone Jul 2, 2022
@adamjstewart adamjstewart enabled auto-merge (squash) July 2, 2022 17:39
@adamjstewart adamjstewart merged commit c3e11e4 into main Jul 2, 2022
@adamjstewart adamjstewart deleted the ignore_zeros_fix branch July 2, 2022 17:44
@adamjstewart adamjstewart added the backwards-incompatible Changes that are not backwards compatible label Jul 11, 2022
@adamjstewart adamjstewart mentioned this pull request Jul 11, 2022
@adamjstewart adamjstewart mentioned this pull request Sep 15, 2022
yichiac pushed a commit to yichiac/torchgeo that referenced this pull request Apr 29, 2023
)

* Clarify the ignore_zeros parameter to the segmentationi trainer

* Black

* Add test

* Added warnings

* Renaming ignore_zeros to ignore_index

* Fixed rest of config and tests

* Update conf/chesapeake_cvpr.yaml

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>

* Update torchgeo/trainers/segmentation.py

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>

* Update torchgeo/trainers/segmentation.py

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>

* Changed warning match

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-incompatible Changes that are not backwards compatible testing Continuous integration testing trainers PyTorch Lightning trainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: missing "not" operator to set ignore_zeros in segmentation trainer
2 participants