-
Notifications
You must be signed in to change notification settings - Fork 7.2k
GaussianBlur CV-CUDA Backend #9280
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
base: main
Are you sure you want to change the base?
Changes from all commits
44db71c
e3dd700
c035df1
98d7dfb
ddc116d
e51dc7e
e14e210
4939355
ac82cea
b18fedf
5df3a7d
9cd7582
d9e3f83
ccd4c1d
b3d7814
160e047
5ce83b1
3bcc517
2edfdff
1155607
8c2cb57
e886fc0
71ea23c
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import torchvision.transforms.v2 as transforms | ||
|
|
||
| from common_utils import ( | ||
| assert_close, | ||
| assert_equal, | ||
| cache, | ||
| cpu_and_cuda, | ||
|
|
@@ -41,7 +42,6 @@ | |
| ) | ||
|
|
||
| from torch import nn | ||
| from torch.testing import assert_close | ||
| from torch.utils._pytree import tree_flatten, tree_map | ||
| from torch.utils.data import DataLoader, default_collate | ||
| from torchvision import tv_tensors | ||
|
|
@@ -3936,7 +3936,15 @@ def test_kernel_video(self): | |
|
|
||
| @pytest.mark.parametrize( | ||
| "make_input", | ||
| [make_image_tensor, make_image_pil, make_image, make_video], | ||
| [ | ||
| make_image_tensor, | ||
| make_image_pil, | ||
| make_image, | ||
| make_video, | ||
| pytest.param( | ||
| make_image_cvcuda, marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available") | ||
|
Contributor
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. See this PR: https://github.com/pytorch/vision/pull/9305/changes There are other parts with similar issues that also need to be addressed. |
||
| ), | ||
| ], | ||
| ) | ||
| def test_functional(self, make_input): | ||
| check_functional(F.gaussian_blur, make_input(), kernel_size=(3, 3)) | ||
|
|
@@ -3948,14 +3956,31 @@ def test_functional(self, make_input): | |
| (F._misc._gaussian_blur_image_pil, PIL.Image.Image), | ||
| (F.gaussian_blur_image, tv_tensors.Image), | ||
| (F.gaussian_blur_video, tv_tensors.Video), | ||
| pytest.param( | ||
| F._misc._gaussian_blur_image_cvcuda, | ||
| None, | ||
| marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"), | ||
| ), | ||
| ], | ||
| ) | ||
| def test_functional_signature(self, kernel, input_type): | ||
| if kernel is F._misc._gaussian_blur_image_cvcuda: | ||
| input_type = _import_cvcuda().Tensor | ||
| check_functional_kernel_signature_match(F.gaussian_blur, kernel=kernel, input_type=input_type) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "make_input", | ||
| [make_image_tensor, make_image_pil, make_image, make_bounding_boxes, make_segmentation_mask, make_video], | ||
| [ | ||
| make_image_tensor, | ||
| make_image_pil, | ||
| make_image, | ||
| make_bounding_boxes, | ||
| make_segmentation_mask, | ||
| make_video, | ||
| pytest.param( | ||
| make_image_cvcuda, marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available") | ||
| ), | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize("device", cpu_and_cuda()) | ||
| @pytest.mark.parametrize("sigma", [5, 2.0, (0.5, 2), [1.3, 2.7]]) | ||
|
|
@@ -4018,11 +4043,22 @@ def test_make_params(self, sigma): | |
| ((1, 26, 28), (23, 23), 1.7), | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize("dtype", [torch.float32, torch.float64, torch.float16]) | ||
| @pytest.mark.parametrize("dtype", [torch.uint8, torch.float32, torch.float64, torch.float16]) | ||
| @pytest.mark.parametrize("device", cpu_and_cuda()) | ||
| def test_functional_image_correctness(self, dimensions, kernel_size, sigma, dtype, device): | ||
| @pytest.mark.parametrize( | ||
| "input_type", | ||
| [ | ||
| tv_tensors.Image, | ||
| pytest.param( | ||
| "cvcuda.Tensor", marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA not available") | ||
| ), | ||
| ], | ||
| ) | ||
| def test_functional_image_correctness(self, dimensions, kernel_size, sigma, dtype, device, input_type): | ||
| if dtype is torch.float16 and device == "cpu": | ||
| pytest.skip("The CPU implementation of float16 on CPU differs from opencv") | ||
| if (dtype != torch.float32 and dtype != torch.uint8) and input_type == "cvcuda.Tensor": | ||
| pytest.skip("CVCUDA does not support non-float32 or uint8 dtypes for gaussian blur") | ||
|
Contributor
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. I feel that this comment is bit confusing:
Thus, I recommend to use "CVCUDA only supports float32 and uint8 dtypes for gaussian blur". |
||
|
|
||
| num_channels, height, width = dimensions | ||
|
|
||
|
|
@@ -4042,9 +4078,17 @@ def test_functional_image_correctness(self, dimensions, kernel_size, sigma, dtyp | |
| device=device, | ||
| ) | ||
|
|
||
| actual = F.gaussian_blur_image(image, kernel_size=kernel_size, sigma=sigma) | ||
| if input_type == "cvcuda.Tensor": | ||
| image = image.unsqueeze(0) | ||
| image = F.to_cvcuda_tensor(image) | ||
|
|
||
| torch.testing.assert_close(actual, expected, rtol=0, atol=1) | ||
| actual = F.gaussian_blur(image, kernel_size=kernel_size, sigma=sigma) | ||
|
|
||
| if input_type == "cvcuda.Tensor": | ||
| actual = F.cvcuda_to_tensor(actual) | ||
| actual = actual.squeeze(0).to(device=device) | ||
|
Contributor
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. We can also use
Contributor
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. I think we can also use |
||
|
|
||
| assert_close(actual, expected, rtol=0, atol=1) | ||
|
|
||
|
|
||
| class TestGaussianNoise: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.