-
Notifications
You must be signed in to change notification settings - Fork 403
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
Conversation
y1 = round((height - size) / 2) | ||
x1 = round((width - size) / 2) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #675 (comment)
) | ||
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))) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* 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
* 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
* 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
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