|
21 | 21 | import torchvision.transforms.v2 as transforms |
22 | 22 |
|
23 | 23 | from common_utils import ( |
| 24 | + assert_close, |
24 | 25 | assert_equal, |
25 | 26 | cache, |
26 | 27 | cpu_and_cuda, |
| 28 | + cvcuda_to_pil_compatible_tensor, |
27 | 29 | freeze_rng_state, |
28 | 30 | ignore_jit_no_profile_information_warning, |
29 | 31 | make_bounding_boxes, |
|
41 | 43 | ) |
42 | 44 |
|
43 | 45 | from torch import nn |
44 | | -from torch.testing import assert_close |
45 | 46 | from torch.utils._pytree import tree_flatten, tree_map |
46 | 47 | from torch.utils.data import DataLoader, default_collate |
47 | 48 | from torchvision import tv_tensors |
@@ -5500,17 +5501,17 @@ def test_kernel_image(self, mean, std, device): |
5500 | 5501 |
|
5501 | 5502 | @pytest.mark.parametrize("device", cpu_and_cuda()) |
5502 | 5503 | def test_kernel_image_inplace(self, device): |
5503 | | - input = make_image_tensor(dtype=torch.float32, device=device) |
5504 | | - input_version = input._version |
| 5504 | + inpt = make_image_tensor(dtype=torch.float32, device=device) |
| 5505 | + input_version = inpt._version |
5505 | 5506 |
|
5506 | | - output_out_of_place = F.normalize_image(input, mean=self.MEAN, std=self.STD) |
5507 | | - assert output_out_of_place.data_ptr() != input.data_ptr() |
5508 | | - assert output_out_of_place is not input |
| 5507 | + output_out_of_place = F.normalize_image(inpt, mean=self.MEAN, std=self.STD) |
| 5508 | + assert output_out_of_place.data_ptr() != inpt.data_ptr() |
| 5509 | + assert output_out_of_place is not inpt |
5509 | 5510 |
|
5510 | | - output_inplace = F.normalize_image(input, mean=self.MEAN, std=self.STD, inplace=True) |
5511 | | - assert output_inplace.data_ptr() == input.data_ptr() |
| 5511 | + output_inplace = F.normalize_image(inpt, mean=self.MEAN, std=self.STD, inplace=True) |
| 5512 | + assert output_inplace.data_ptr() == inpt.data_ptr() |
5512 | 5513 | assert output_inplace._version > input_version |
5513 | | - assert output_inplace is input |
| 5514 | + assert output_inplace is inpt |
5514 | 5515 |
|
5515 | 5516 | assert_equal(output_inplace, output_out_of_place) |
5516 | 5517 |
|
@@ -5560,9 +5561,9 @@ def test_functional_error(self): |
5560 | 5561 | with pytest.raises(ValueError, match="std evaluated to zero, leading to division by zero"): |
5561 | 5562 | F.normalize_image(make_image(dtype=torch.float32), mean=self.MEAN, std=std) |
5562 | 5563 |
|
5563 | | - def _sample_input_adapter(self, transform, input, device): |
| 5564 | + def _sample_input_adapter(self, transform, inpt, device): |
5564 | 5565 | adapted_input = {} |
5565 | | - for key, value in input.items(): |
| 5566 | + for key, value in inpt.items(): |
5566 | 5567 | if isinstance(value, PIL.Image.Image): |
5567 | 5568 | # normalize doesn't support PIL images |
5568 | 5569 | continue |
@@ -5616,15 +5617,12 @@ def test_correctness_image(self, mean, std, dtype, make_input, fn): |
5616 | 5617 | actual = fn(image, mean=mean, std=std) |
5617 | 5618 |
|
5618 | 5619 | if make_input == make_image_cvcuda: |
5619 | | - image = F.cvcuda_to_tensor(image).to(device="cpu") |
5620 | | - image = image.squeeze(0) |
5621 | | - actual = F.cvcuda_to_tensor(actual).to(device="cpu") |
5622 | | - actual = actual.squeeze(0) |
| 5620 | + image = cvcuda_to_pil_compatible_tensor(image) |
5623 | 5621 |
|
5624 | 5622 | expected = self._reference_normalize_image(image, mean=mean, std=std) |
5625 | 5623 |
|
5626 | 5624 | if make_input == make_image_cvcuda: |
5627 | | - torch.testing.assert_close(actual, expected, rtol=0, atol=1e-6) |
| 5625 | + assert_close(actual, expected, rtol=0, atol=1e-6) |
5628 | 5626 | else: |
5629 | 5627 | assert_equal(actual, expected) |
5630 | 5628 |
|
|
0 commit comments