-
Notifications
You must be signed in to change notification settings - Fork 7.1k
make clamp_bounding_box a kernel / dispatcher hybrid #7227
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b639a2f
make clamp_bounding_box a kernel / dispatcher hybrid
pmeier 7572245
make condition more strict
pmeier b8ce022
Merge branch 'main' into clamp-bbox-dipatcher
pmeier d2b0dde
fix transform
pmeier 3dffd17
use ValueError over RuntimeError
pmeier 7c68623
add tests for errors
pmeier 0213afb
Merge branch 'main' into clamp-bbox-dipatcher
pmeier 40a1df1
Merge branch 'clamp-bbox-dipatcher' of https://github.com/pmeier/visi…
pmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,12 +155,14 @@ def _unbatch(self, batch, *, data_dims): | |
if batched_tensor.ndim == data_dims: | ||
return batch | ||
|
||
return [ | ||
self._unbatch(unbatched, data_dims=data_dims) | ||
for unbatched in ( | ||
batched_tensor.unbind(0) if not metadata else [(t, *metadata) for t in batched_tensor.unbind(0)] | ||
) | ||
] | ||
unbatcheds = [] | ||
for unbatched in ( | ||
batched_tensor.unbind(0) if not metadata else [(t, *metadata) for t in batched_tensor.unbind(0)] | ||
): | ||
if isinstance(batch, datapoints._datapoint.Datapoint): | ||
unbatched = type(batch).wrap_like(batch, unbatched) | ||
Comment on lines
+162
to
+163
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. Small fix since this didn't respect datapoints types before. This was not an issue, since this is called from a kernel test and so far all kernels operated only with plain tensors. Meaning, all datapoints would have been unwrapped anyway. |
||
unbatcheds.append(self._unbatch(unbatched, data_dims=data_dims)) | ||
return unbatcheds | ||
|
||
@sample_inputs | ||
@pytest.mark.parametrize("device", cpu_and_gpu()) | ||
|
@@ -558,6 +560,36 @@ def assert_samples_from_standard_normal(t): | |
assert_samples_from_standard_normal(F.normalize_image_tensor(image, mean, std)) | ||
|
||
|
||
class TestClampBoundingBox: | ||
@pytest.mark.parametrize( | ||
"metadata", | ||
[ | ||
dict(), | ||
dict(format=datapoints.BoundingBoxFormat.XYXY), | ||
dict(spatial_size=(1, 1)), | ||
], | ||
) | ||
def test_simple_tensor_insufficient_metadata(self, metadata): | ||
simple_tensor = next(make_bounding_boxes()).as_subclass(torch.Tensor) | ||
|
||
with pytest.raises(ValueError, match="simple tensor"): | ||
F.clamp_bounding_box(simple_tensor, **metadata) | ||
|
||
@pytest.mark.parametrize( | ||
"metadata", | ||
[ | ||
dict(format=datapoints.BoundingBoxFormat.XYXY), | ||
dict(spatial_size=(1, 1)), | ||
dict(format=datapoints.BoundingBoxFormat.XYXY, spatial_size=(1, 1)), | ||
], | ||
) | ||
def test_datapoint_explicit_metadata(self, metadata): | ||
datapoint = next(make_bounding_boxes()) | ||
|
||
with pytest.raises(ValueError, match="bounding box datapoint"): | ||
F.clamp_bounding_box(datapoint, **metadata) | ||
|
||
|
||
# TODO: All correctness checks below this line should be ported to be references on a `KernelInfo` in | ||
# `prototype_transforms_kernel_infos.py` | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 quick and dirty. If we have more such cases in the future, we should have something like an
unwrap
method or the like to get the plain tensor.