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

Adding ETCI2021 datamodule and trainer #234

Merged
merged 20 commits into from
Nov 14, 2021
Merged

Adding ETCI2021 datamodule and trainer #234

merged 20 commits into from
Nov 14, 2021

Conversation

Copy link
Collaborator

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

Needs to be added to docs

torchgeo/datasets/etci2021.py Outdated Show resolved Hide resolved
torchgeo/datasets/etci2021.py Outdated Show resolved Hide resolved
torchgeo/datasets/etci2021.py Outdated Show resolved Hide resolved
torchgeo/trainers/__init__.py Outdated Show resolved Hide resolved
torchgeo/trainers/etci2021.py Outdated Show resolved Hide resolved
@@ -77,19 +77,28 @@ def __init__(self, **kwargs: Any) -> None:
in_channels: Number of channels in input image
num_classes: Number of semantic classes to predict
loss: Name of the loss function
ignore_zeros: Whether to ignore the "0" class value in the loss and metrics
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not call it "ignore_index" and make it an int that defaults to zero? That gives the most flexibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because nn.CrossEntropyLoss uses -1000 as a None value so there is not an easy way to not ignore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure I understand. I'm saying to rename the ignore_zeros parameter to ignore_index and have it accept an int, not to remove the parameter entirely.

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 know, but say I don't want to ignore anything -- I can't pass None because nn.CrossEntropyLoss behaves differently than everything else that accepts ignore_index

@adamjstewart adamjstewart added datasets Geospatial or benchmark datasets trainers PyTorch Lightning trainers labels Nov 10, 2021
@calebrob6
Copy link
Member Author

@adamjstewart how do you want to test the plot methods?

docs/conf.py Outdated Show resolved Hide resolved
tests/datasets/test_etci2021.py Outdated Show resolved Hide resolved
torchgeo/trainers/etci2021.py Outdated Show resolved Hide resolved
@adamjstewart
Copy link
Collaborator

@adamjstewart how do you want to test the plot methods?

I would personally be fine with a simple test that just runs plot and makes sure it doesn't crash, but if you want to write a more detailed test you can check the figure object for all of the expected attributes. I once wrote a bunch of matplotlib auto-grading stuff for a class I was TAing.

@calebrob6
Copy link
Member Author

Relevant bit for later

        x = batch["image"]
        y = batch["mask"]
        with torch.no_grad():
            # Kornia expects masks to be [B, C, H, W] format with float values while
            # torch losses like cross entropy expect masks to be in [B, H, W] format
            # with long values. We'll just assume that samples are in a format that
            # torch expects and adjust accordingly if we need to do augmentations.
            x, y = self.train_augmentations(x, y.unsqueeze(1).float())
        y = y.long().squeeze()

@calebrob6
Copy link
Member Author

I removed the trainer and reset the test data as I can't be bothered to jump through all these hoops.

Note, this dataset does need augmentations as training will overfit to the train split (the test set is sampled from a different geographic location and those inputs are likely out-of-distribution to the training data).

The above comment is the relevant part to add to train_step for augmentation that explains what kornia augmentations are expecting in terms of dimensions.

@calebrob6 calebrob6 mentioned this pull request Nov 13, 2021
@adamjstewart adamjstewart merged commit fca579a into main Nov 14, 2021
@adamjstewart adamjstewart deleted the etci2021 branch November 14, 2021 20:31
@adamjstewart adamjstewart added this to the 0.2.0 milestone Nov 20, 2021
@adamjstewart adamjstewart added datamodules PyTorch Lightning datamodules utilities Utilities for working with geospatial data and removed trainers PyTorch Lightning trainers utilities Utilities for working with geospatial data labels Jan 2, 2022
yichiac pushed a commit to yichiac/torchgeo that referenced this pull request Apr 29, 2023
* Adding ETCI2021 datamodule and trainer

* Fixing confs

* Update torchgeo/datasets/etci2021.py

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

* Update torchgeo/trainers/etci2021.py

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

* Update conf.py

* Reverting trainer init

* plot method

* Update ETCI2021 test data

* Test trainer

* Fix train.py

* Fix test

* Adding matplotlib intersphinx

* Remove ignore

* Revert "Update ETCI2021 test data"

This reverts commit 502a378.

* Remove stuff

* Reset

* Add plot tests

* Unzipping test data

* Test datamodule

* Add datamodule to docs

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
datamodules PyTorch Lightning datamodules datasets Geospatial or benchmark datasets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants