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

Concerns with GridGeoSampler for evaluation #1245

Closed
adamjstewart opened this issue Apr 14, 2023 · 4 comments
Closed

Concerns with GridGeoSampler for evaluation #1245

adamjstewart opened this issue Apr 14, 2023 · 4 comments
Assignees
Labels
samplers Samplers for indexing datasets
Projects
Milestone

Comments

@adamjstewart
Copy link
Collaborator

adamjstewart commented Apr 14, 2023

A couple of issues that may affect the usage of GridGeoSampler for benchmarking.

Overlapping patches

Back in #630, we modified GridGeoSampler to ensure that every part of the image is sampled from, even if the height/width of the image is not a multiple of the stride. At the time, I decided that we should adjust the stride of the last row/col in order to avoid sampling outside of the bounds of the image. In hindsight, I think this was a mistake.

The problem is that we end up with the last row/col overlapping with the second-to-last row/col, resulting in some areas being double counted when computing performance metrics. It also makes stitching together prediction patches unnecessarily complicated.

I think we should modify GridGeoSampler to avoid adjusting stride and instead sample outside the bounds of the image. I believe rasterio will simply return nodata pixels for areas outside of the image. @remtav are you okay with this solution? I believe this was actually the first idea you implemented, apologies for pushing that PR in the wrong direction.

Technically this issue also occurs when multiple images in the dataset intersect, but this is harder to mitigate without storing all predictions in one giant tensor and computing performance only on the final predicted mask. I think we would run out of memory very quickly.

ignore_index weighting

This one may also affect training for other GeoSamplers as well, although I'm most concerned about evaluation.

When sampling from large tiles, many patches will contain partial or complete nodata pixels. TorchMetrics allows us to ignore these areas using ignore_index. However, it's unclear to me if all patches are weighted equally when computing the final performance metrics with Lightning. Ideally, the overall reported accuracy would match regardless of whether we chip up the image into small patches or if we compute accuracy on the entire image/mask in one go.

We could peruse the internals of TorchMetrics and Lightning, but I think it's actually easier to construct a toy example to determine whether or not this issue occurs. Consider an image with width 200 and height 100. Let the first 99 columns of the ground truth mask be 0, the 100th column be 1, and the last 100 columns be 2. Let the predicted mask be a tensor of all 1s. If we use a GridGeoSampler with size 100 and stride 100, and let ignore_index=0, the correct performance should be ~1%. If the actual reported performance is 50%, we'll know we have an issue.

@adamjstewart adamjstewart added the samplers Samplers for indexing datasets label Apr 14, 2023
@adamjstewart adamjstewart added this to the 0.4.2 milestone Apr 14, 2023
@adamjstewart adamjstewart added this to To do in SSL4EO-L via automation Apr 14, 2023
@calebrob6
Copy link
Member

I'm fine with this, and can take it.

@calebrob6 calebrob6 self-assigned this Apr 14, 2023
@adamjstewart
Copy link
Collaborator Author

@calebrob6 any updates on this?

@remtav
Copy link
Contributor

remtav commented Apr 27, 2023

With some delay, no trouble with this on my end. Thanks for asking.

@adamjstewart
Copy link
Collaborator Author

Closed by #1329 and #1331

SSL4EO-L automation moved this from To do to Done May 14, 2023
@adamjstewart adamjstewart modified the milestones: 0.4.2, 0.5.0 Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samplers Samplers for indexing datasets
Projects
No open projects
Development

No branches or pull requests

3 participants