-
Notifications
You must be signed in to change notification settings - Fork 407
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
RandomGeoSampler: fix performance regression #1968
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,17 +56,16 @@ def get_random_bounding_box( | |
""" | ||
t_size = _to_tuple(size) | ||
|
||
width = (bounds.maxx - bounds.minx - t_size[1]) // res | ||
height = (bounds.maxy - bounds.miny - t_size[0]) // res | ||
# May be negative if bounding box is smaller than patch size | ||
width = (bounds.maxx - bounds.minx - t_size[1]) / res | ||
height = (bounds.maxy - bounds.miny - t_size[0]) / res | ||
|
||
minx = bounds.minx | ||
miny = bounds.miny | ||
|
||
# random.randrange crashes for inputs <= 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a dead comment, we no longer use |
||
if width > 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer need to guard for negative numbers, it doesn't matter if the sample starts outside the bounds of the image for bounding boxes smaller than the patch size. |
||
minx += torch.rand(1).item() * width * res | ||
if height > 0: | ||
miny += torch.rand(1).item() * height * res | ||
# Use an integer multiple of res to avoid resampling | ||
minx += int(torch.rand(1).item() * width) * res | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only real important line |
||
miny += int(torch.rand(1).item() * height) * res | ||
|
||
maxx = minx + t_size[1] | ||
maxy = miny + t_size[0] | ||
|
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.
This is the width/height in pixel units. It no longer needs to be an integer, float is fine too. We cast to integer elsewhere.