Skip to content

Commit 1e7ccba

Browse files
committed
Merge branch 'main' into port-random-zoom-out
2 parents 9dd75c8 + c3aee87 commit 1e7ccba

File tree

9 files changed

+61
-30
lines changed

9 files changed

+61
-30
lines changed

references/segmentation/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def compute(self):
8888
return acc_global, acc, iu
8989

9090
def reduce_from_all_processes(self):
91-
reduce_across_processes(self.mat)
91+
self.mat = reduce_across_processes(self.mat).to(torch.int64)
9292

9393
def __str__(self):
9494
acc_global, acc, iu = self.compute()

test/test_datasets_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ def url_parametrization(*dataset_urls_and_ids_fns):
368368
kinetics,
369369
kitti,
370370
places365,
371+
sbu,
371372
)
372373
def test_url_is_accessible(url):
373374
"""
@@ -379,7 +380,6 @@ def test_url_is_accessible(url):
379380

380381
@url_parametrization(
381382
stanford_cars, # https://github.com/pytorch/vision/issues/7545
382-
sbu, # https://github.com/pytorch/vision/issues/7964
383383
)
384384
@pytest.mark.xfail
385385
def test_url_is_not_accessible(url):

test/test_onnx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def to_numpy(tensor):
7979
inputs = list(map(to_numpy, inputs))
8080
outputs = list(map(to_numpy, outputs))
8181

82-
ort_session = onnxruntime.InferenceSession(onnx_io.getvalue())
82+
ort_session = onnxruntime.InferenceSession(onnx_io.getvalue(), providers=onnxruntime.get_available_providers())
8383
# compute onnxruntime output prediction
8484
ort_inputs = {ort_session.get_inputs()[i].name: inpt for i, inpt in enumerate(inputs)}
8585
ort_outs = ort_session.run(None, ort_inputs)

test/test_transforms_v2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,9 @@ class TestSmoke:
116116
(transforms.RandAugment(), auto_augment_adapter),
117117
(transforms.TrivialAugmentWide(), auto_augment_adapter),
118118
(transforms.ColorJitter(brightness=0.1, contrast=0.2, saturation=0.3, hue=0.15), None),
119-
(transforms.Grayscale(), None),
120119
(transforms.RandomAdjustSharpness(sharpness_factor=0.5, p=1.0), None),
121120
(transforms.RandomAutocontrast(p=1.0), None),
122121
(transforms.RandomEqualize(p=1.0), None),
123-
(transforms.RandomGrayscale(p=1.0), None),
124122
(transforms.RandomInvert(p=1.0), None),
125123
(transforms.RandomChannelPermutation(), None),
126124
(transforms.RandomPhotometricDistort(p=1.0), None),

test/test_transforms_v2_consistency.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ def __init__(
122122
(torch.float32, torch.float64),
123123
]
124124
],
125-
ConsistencyConfig(
126-
v2_transforms.Grayscale,
127-
legacy_transforms.Grayscale,
128-
[
129-
ArgsKwargs(num_output_channels=1),
130-
ArgsKwargs(num_output_channels=3),
131-
],
132-
make_images_kwargs=dict(DEFAULT_MAKE_IMAGES_KWARGS, color_spaces=["RGB", "GRAY"]),
133-
# Use default tolerances of `torch.testing.assert_close`
134-
closeness_kwargs=dict(rtol=None, atol=None),
135-
),
136125
ConsistencyConfig(
137126
v2_transforms.ToPILImage,
138127
legacy_transforms.ToPILImage,
@@ -217,17 +206,6 @@ def __init__(
217206
],
218207
closeness_kwargs={"atol": 1e-6, "rtol": 1e-6},
219208
),
220-
ConsistencyConfig(
221-
v2_transforms.RandomGrayscale,
222-
legacy_transforms.RandomGrayscale,
223-
[
224-
ArgsKwargs(p=0),
225-
ArgsKwargs(p=1),
226-
],
227-
make_images_kwargs=dict(DEFAULT_MAKE_IMAGES_KWARGS, color_spaces=["RGB", "GRAY"]),
228-
# Use default tolerances of `torch.testing.assert_close`
229-
closeness_kwargs=dict(rtol=None, atol=None),
230-
),
231209
ConsistencyConfig(
232210
v2_transforms.PILToTensor,
233211
legacy_transforms.PILToTensor,

test/test_transforms_v2_refactored.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,6 +3947,61 @@ def test_transform_correctness(self, brightness, contrast, saturation, hue):
39473947
assert mae < 2
39483948

39493949

3950+
class TestRgbToGrayscale:
3951+
@pytest.mark.parametrize("dtype", [torch.uint8, torch.float32])
3952+
@pytest.mark.parametrize("device", cpu_and_cuda())
3953+
def test_kernel_image(self, dtype, device):
3954+
check_kernel(F.rgb_to_grayscale_image, make_image(dtype=dtype, device=device))
3955+
3956+
@pytest.mark.parametrize("make_input", [make_image_tensor, make_image_pil, make_image])
3957+
def test_functional(self, make_input):
3958+
check_functional(F.rgb_to_grayscale, make_input())
3959+
3960+
@pytest.mark.parametrize(
3961+
("kernel", "input_type"),
3962+
[
3963+
(F.rgb_to_grayscale_image, torch.Tensor),
3964+
(F._rgb_to_grayscale_image_pil, PIL.Image.Image),
3965+
(F.rgb_to_grayscale_image, tv_tensors.Image),
3966+
],
3967+
)
3968+
def test_functional_signature(self, kernel, input_type):
3969+
check_functional_kernel_signature_match(F.rgb_to_grayscale, kernel=kernel, input_type=input_type)
3970+
3971+
@pytest.mark.parametrize("transform", [transforms.Grayscale(), transforms.RandomGrayscale(p=1)])
3972+
@pytest.mark.parametrize("make_input", [make_image_tensor, make_image_pil, make_image])
3973+
def test_transform(self, transform, make_input):
3974+
check_transform(transform, make_input())
3975+
3976+
@pytest.mark.parametrize("num_output_channels", [1, 3])
3977+
@pytest.mark.parametrize("fn", [F.rgb_to_grayscale, transform_cls_to_functional(transforms.Grayscale)])
3978+
def test_image_correctness(self, num_output_channels, fn):
3979+
image = make_image(dtype=torch.uint8, device="cpu")
3980+
3981+
actual = fn(image, num_output_channels=num_output_channels)
3982+
expected = F.to_image(F.rgb_to_grayscale(F.to_pil_image(image), num_output_channels=num_output_channels))
3983+
3984+
assert_equal(actual, expected, rtol=0, atol=1)
3985+
3986+
@pytest.mark.parametrize("num_input_channels", [1, 3])
3987+
def test_random_transform_correctness(self, num_input_channels):
3988+
image = make_image(
3989+
color_space={
3990+
1: "GRAY",
3991+
3: "RGB",
3992+
}[num_input_channels],
3993+
dtype=torch.uint8,
3994+
device="cpu",
3995+
)
3996+
3997+
transform = transforms.RandomGrayscale(p=1)
3998+
3999+
actual = transform(image)
4000+
expected = F.to_image(F.rgb_to_grayscale(F.to_pil_image(image), num_output_channels=num_input_channels))
4001+
4002+
assert_equal(actual, expected, rtol=0, atol=1)
4003+
4004+
39504005
class TestRandomZoomOut:
39514006
@pytest.mark.parametrize(
39524007
"make_input",

torchvision/transforms/functional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ def erase(img: Tensor, i: int, j: int, h: int, w: int, v: Tensor, inplace: bool
13261326
def gaussian_blur(img: Tensor, kernel_size: List[int], sigma: Optional[List[float]] = None) -> Tensor:
13271327
"""Performs Gaussian blurring on the image by given kernel.
13281328
If the image is torch Tensor, it is expected
1329-
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions.
1329+
to have [..., H, W] shape, where ... means at most one leading dimension.
13301330
13311331
Args:
13321332
img (PIL Image or Tensor): Image to be blurred

torchvision/transforms/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ def __repr__(self) -> str:
17601760
class GaussianBlur(torch.nn.Module):
17611761
"""Blurs image with randomly chosen Gaussian blur.
17621762
If the image is torch Tensor, it is expected
1763-
to have [..., C, H, W] shape, where ... means an arbitrary number of leading dimensions.
1763+
to have [..., C, H, W] shape, where ... means at most one leading dimension.
17641764
17651765
Args:
17661766
kernel_size (int or sequence): Size of the Gaussian kernel.

torchvision/transforms/v2/_type_conversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _transform(
7979

8080

8181
class ToPureTensor(Transform):
82-
"""[BETA] Convert all tv_tensors to pure tensors, removing associated metadata (if any).
82+
"""[BETA] Convert all TVTensors to pure tensors, removing associated metadata (if any).
8383
8484
.. v2betastatus:: ToPureTensor transform
8585

0 commit comments

Comments
 (0)