-
Notifications
You must be signed in to change notification settings - Fork 7.2k
expand has_any and has_all to also accept check callables #6447
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
10 commits
Select commit
Hold shift + click to select a range
02f518f
expand has_any and has_all to also accept check callables
pmeier 1f12ca7
add test and fix has_all
pmeier ae09241
Merge branch 'main' into expand-has-utils
pmeier ed39943
add support for simple tensor images to CutMix, MixUp and RandomIoUCrop
pmeier 4784b8b
remove TODO
pmeier 86a7cf2
remove pythonic syntax sugar
pmeier f276362
simplify
pmeier 6f22eda
use concreate examples in test rather than abstract ones
pmeier 4ea9bef
simplify further
pmeier bb8700e
Merge branch 'main' into expand-has-utils
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import PIL.Image | ||
| import pytest | ||
|
|
||
| import torch | ||
|
|
||
| from test_prototype_transforms_functional import make_bounding_box, make_image, make_segmentation_mask | ||
|
|
||
| from torchvision.prototype import features | ||
| from torchvision.prototype.transforms._utils import has_all, has_any, is_simple_tensor | ||
| from torchvision.prototype.transforms.functional import to_image_pil | ||
|
|
||
|
|
||
| IMAGE = make_image(color_space=features.ColorSpace.RGB) | ||
| BOUNDING_BOX = make_bounding_box(format=features.BoundingBoxFormat.XYXY, image_size=IMAGE.image_size) | ||
| SEGMENTATION_MASK = make_segmentation_mask(size=IMAGE.image_size) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("sample", "types", "expected"), | ||
| [ | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.Image,), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.BoundingBox,), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.SegmentationMask,), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.Image, features.BoundingBox), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.Image, features.SegmentationMask), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.BoundingBox, features.SegmentationMask), True), | ||
| ((SEGMENTATION_MASK,), (features.Image, features.BoundingBox), False), | ||
| ((BOUNDING_BOX,), (features.Image, features.SegmentationMask), False), | ||
| ((IMAGE,), (features.BoundingBox, features.SegmentationMask), False), | ||
| ( | ||
| (IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), | ||
| (features.Image, features.BoundingBox, features.SegmentationMask), | ||
| True, | ||
| ), | ||
| ((), (features.Image, features.BoundingBox, features.SegmentationMask), False), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (lambda obj: isinstance(obj, features.Image),), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (lambda _: False,), False), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (lambda _: True,), True), | ||
| ((IMAGE,), (features.Image, PIL.Image.Image, is_simple_tensor), True), | ||
| ((torch.Tensor(IMAGE),), (features.Image, PIL.Image.Image, is_simple_tensor), True), | ||
| ((to_image_pil(IMAGE),), (features.Image, PIL.Image.Image, is_simple_tensor), True), | ||
| ], | ||
| ) | ||
| def test_has_any(sample, types, expected): | ||
| assert has_any(sample, *types) is expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("sample", "types", "expected"), | ||
| [ | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.Image,), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.BoundingBox,), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.SegmentationMask,), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.Image, features.BoundingBox), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.Image, features.SegmentationMask), True), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (features.BoundingBox, features.SegmentationMask), True), | ||
| ( | ||
| (IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), | ||
| (features.Image, features.BoundingBox, features.SegmentationMask), | ||
| True, | ||
| ), | ||
| ((BOUNDING_BOX, SEGMENTATION_MASK), (features.Image, features.BoundingBox), False), | ||
| ((BOUNDING_BOX, SEGMENTATION_MASK), (features.Image, features.SegmentationMask), False), | ||
| ((IMAGE, SEGMENTATION_MASK), (features.BoundingBox, features.SegmentationMask), False), | ||
| ( | ||
| (IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), | ||
| (features.Image, features.BoundingBox, features.SegmentationMask), | ||
| True, | ||
| ), | ||
| ((BOUNDING_BOX, SEGMENTATION_MASK), (features.Image, features.BoundingBox, features.SegmentationMask), False), | ||
| ((IMAGE, SEGMENTATION_MASK), (features.Image, features.BoundingBox, features.SegmentationMask), False), | ||
| ((IMAGE, BOUNDING_BOX), (features.Image, features.BoundingBox, features.SegmentationMask), False), | ||
| ( | ||
| (IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), | ||
| (lambda obj: isinstance(obj, (features.Image, features.BoundingBox, features.SegmentationMask)),), | ||
| True, | ||
| ), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (lambda _: False,), False), | ||
| ((IMAGE, BOUNDING_BOX, SEGMENTATION_MASK), (lambda _: True,), True), | ||
| ], | ||
| ) | ||
| def test_has_all(sample, types, expected): | ||
| assert has_all(sample, *types) is expected |
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
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.
They are asymmetric because the behavior we want for
has_anyisany(any(...))and forhas_allisany(all(...)). Ifhas_allwould beall(all(...))they would be symmetric.