|
1 | 1 | import itertools
|
2 | 2 | import re
|
| 3 | +import warnings |
3 | 4 | from collections import defaultdict
|
4 | 5 |
|
5 | 6 | import numpy as np
|
@@ -94,7 +95,7 @@ def parametrize_from_transforms(*transforms):
|
94 | 95 | class TestSmoke:
|
95 | 96 | @parametrize_from_transforms(
|
96 | 97 | transforms.RandomErasing(p=1.0),
|
97 |
| - transforms.Resize([16, 16]), |
| 98 | + transforms.Resize([16, 16], antialias=True), |
98 | 99 | transforms.CenterCrop([16, 16]),
|
99 | 100 | transforms.ConvertDtype(),
|
100 | 101 | transforms.RandomHorizontalFlip(),
|
@@ -210,7 +211,7 @@ def test_normalize(self, transform, input):
|
210 | 211 | @parametrize(
|
211 | 212 | [
|
212 | 213 | (
|
213 |
| - transforms.RandomResizedCrop([16, 16]), |
| 214 | + transforms.RandomResizedCrop([16, 16], antialias=True), |
214 | 215 | itertools.chain(
|
215 | 216 | make_images(extra_dims=[(4,)]),
|
216 | 217 | make_vanilla_tensor_images(),
|
@@ -1991,6 +1992,70 @@ def test__transform(self, inpt):
|
1991 | 1992 | assert output.dtype == inpt.dtype
|
1992 | 1993 |
|
1993 | 1994 |
|
| 1995 | +# TODO: remove this test in 0.17 when the default of antialias changes to True |
| 1996 | +def test_antialias_warning(): |
| 1997 | + pil_img = PIL.Image.new("RGB", size=(10, 10), color=127) |
| 1998 | + tensor_img = torch.randint(0, 256, size=(3, 10, 10), dtype=torch.uint8) |
| 1999 | + tensor_video = torch.randint(0, 256, size=(2, 3, 10, 10), dtype=torch.uint8) |
| 2000 | + |
| 2001 | + match = "The default value of the antialias parameter" |
| 2002 | + with pytest.warns(UserWarning, match=match): |
| 2003 | + transforms.Resize((20, 20))(tensor_img) |
| 2004 | + with pytest.warns(UserWarning, match=match): |
| 2005 | + transforms.RandomResizedCrop((20, 20))(tensor_img) |
| 2006 | + with pytest.warns(UserWarning, match=match): |
| 2007 | + transforms.ScaleJitter((20, 20))(tensor_img) |
| 2008 | + with pytest.warns(UserWarning, match=match): |
| 2009 | + transforms.RandomShortestSize((20, 20))(tensor_img) |
| 2010 | + with pytest.warns(UserWarning, match=match): |
| 2011 | + transforms.RandomResize(10, 20)(tensor_img) |
| 2012 | + |
| 2013 | + with pytest.warns(UserWarning, match=match): |
| 2014 | + transforms.functional.resize(tensor_img, (20, 20)) |
| 2015 | + with pytest.warns(UserWarning, match=match): |
| 2016 | + transforms.functional.resize_image_tensor(tensor_img, (20, 20)) |
| 2017 | + |
| 2018 | + with pytest.warns(UserWarning, match=match): |
| 2019 | + transforms.functional.resize(tensor_video, (20, 20)) |
| 2020 | + with pytest.warns(UserWarning, match=match): |
| 2021 | + transforms.functional.resize_video(tensor_video, (20, 20)) |
| 2022 | + |
| 2023 | + with pytest.warns(UserWarning, match=match): |
| 2024 | + datapoints.Image(tensor_img).resize((20, 20)) |
| 2025 | + with pytest.warns(UserWarning, match=match): |
| 2026 | + datapoints.Image(tensor_img).resized_crop(0, 0, 10, 10, (20, 20)) |
| 2027 | + |
| 2028 | + with pytest.warns(UserWarning, match=match): |
| 2029 | + datapoints.Video(tensor_video).resize((20, 20)) |
| 2030 | + with pytest.warns(UserWarning, match=match): |
| 2031 | + datapoints.Video(tensor_video).resized_crop(0, 0, 10, 10, (20, 20)) |
| 2032 | + |
| 2033 | + with warnings.catch_warnings(): |
| 2034 | + warnings.simplefilter("error") |
| 2035 | + transforms.Resize((20, 20))(pil_img) |
| 2036 | + transforms.RandomResizedCrop((20, 20))(pil_img) |
| 2037 | + transforms.ScaleJitter((20, 20))(pil_img) |
| 2038 | + transforms.RandomShortestSize((20, 20))(pil_img) |
| 2039 | + transforms.RandomResize(10, 20)(pil_img) |
| 2040 | + transforms.functional.resize(pil_img, (20, 20)) |
| 2041 | + |
| 2042 | + transforms.Resize((20, 20), antialias=True)(tensor_img) |
| 2043 | + transforms.RandomResizedCrop((20, 20), antialias=True)(tensor_img) |
| 2044 | + transforms.ScaleJitter((20, 20), antialias=True)(tensor_img) |
| 2045 | + transforms.RandomShortestSize((20, 20), antialias=True)(tensor_img) |
| 2046 | + transforms.RandomResize(10, 20, antialias=True)(tensor_img) |
| 2047 | + |
| 2048 | + transforms.functional.resize(tensor_img, (20, 20), antialias=True) |
| 2049 | + transforms.functional.resize_image_tensor(tensor_img, (20, 20), antialias=True) |
| 2050 | + transforms.functional.resize(tensor_video, (20, 20), antialias=True) |
| 2051 | + transforms.functional.resize_video(tensor_video, (20, 20), antialias=True) |
| 2052 | + |
| 2053 | + datapoints.Image(tensor_img).resize((20, 20), antialias=True) |
| 2054 | + datapoints.Image(tensor_img).resized_crop(0, 0, 10, 10, (20, 20), antialias=True) |
| 2055 | + datapoints.Video(tensor_video).resize((20, 20), antialias=True) |
| 2056 | + datapoints.Video(tensor_video).resized_crop(0, 0, 10, 10, (20, 20), antialias=True) |
| 2057 | + |
| 2058 | + |
1994 | 2059 | @pytest.mark.parametrize("image_type", (PIL.Image, torch.Tensor, datapoints.Image))
|
1995 | 2060 | @pytest.mark.parametrize("label_type", (torch.Tensor, int))
|
1996 | 2061 | @pytest.mark.parametrize("dataset_return_type", (dict, tuple))
|
|
0 commit comments