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

Fix float rounding issues #736

Merged
merged 9 commits into from
Sep 2, 2022
Merged

Fix float rounding issues #736

merged 9 commits into from
Sep 2, 2022

Conversation

adamjstewart
Copy link
Collaborator

@adamjstewart adamjstewart commented Aug 22, 2022

Okay, I checked all uses of int(), round(), math.floor(), math.ceil(), and // in TorchGeo. Found a ton of redundant casts and what I believe to be a few bugs.

Would be great to get a second set of eyes on the changes in this PR and the remaining uses that haven't changed. @TCherici @ashnair1 could I ask you to review this?

Fixes #679

@github-actions github-actions bot added datamodules PyTorch Lightning datamodules datasets Geospatial or benchmark datasets models Models and pretrained weights samplers Samplers for indexing datasets testing Continuous integration testing labels Aug 22, 2022
Comment on lines +154 to +155
y1 = round((height - size) / 2)
x1 = round((width - size) / 2)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pretty sure this is right. The previous logic can't really break, but it could lead to the centered image being shifted by up to 1 pixel. Now, it can be shifted by at most 0.5 pixels.

val_length = int(len(dataset) * val_pct)
test_length = int(len(dataset) * test_pct)
val_length = round(len(dataset) * val_pct)
test_length = round(len(dataset) * test_pct)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

)
masks = torch.tensor(masks).unsqueeze(0)
else:
masks = torch.zeros(size=(1, int(height), int(width)))
masks = torch.zeros(size=(1, round(height), round(width)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Identical to #675

@@ -67,7 +67,7 @@ def test_getitem(self, dataset: ETCI2021) -> None:
assert x["mask"].shape[0] == 1

def test_len(self, dataset: ETCI2021) -> None:
assert len(dataset) == 2
assert len(dataset) == 3
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ETCI2021DataModule uses a 80/20 train/test split. Unfortunately, 80% of 2 is 2, so the test split was empty. Had to increase the size of the dataset by 1 to make the test split non-empty.

@github-actions github-actions bot removed the models Models and pretrained weights label Aug 22, 2022
@adamjstewart adamjstewart added this to the 0.3.1 milestone Aug 22, 2022
@adamjstewart adamjstewart marked this pull request as ready for review August 22, 2022 06:08
@adamjstewart adamjstewart changed the title Fix rounding bugs Fix float rounding issues Aug 22, 2022
Copy link
Collaborator

@isaaccorley isaaccorley left a comment

Choose a reason for hiding this comment

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

lgtm

@adamjstewart adamjstewart merged commit 669a4c0 into main Sep 2, 2022
@adamjstewart adamjstewart deleted the fixes/round branch September 2, 2022 19:08
Modexus pushed a commit to Modexus/torchgeo that referenced this pull request Sep 3, 2022
* Fix rounding bugs

* Mypy fixes

* Undo some changes

* Undo some changes

* mypy fixes

* Fix tests

* Increase size of ETCI2021 fake data

* Undo model changes

* line length fix
adamjstewart added a commit that referenced this pull request Sep 3, 2022
* Fix rounding bugs

* Mypy fixes

* Undo some changes

* Undo some changes

* mypy fixes

* Fix tests

* Increase size of ETCI2021 fake data

* Undo model changes

* line length fix
yichiac pushed a commit to yichiac/torchgeo that referenced this pull request Apr 29, 2023
* Fix rounding bugs

* Mypy fixes

* Undo some changes

* Undo some changes

* mypy fixes

* Fix tests

* Increase size of ETCI2021 fake data

* Undo model changes

* line length fix
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 samplers Samplers for indexing datasets testing Continuous integration testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Various rounding bugs
3 participants