Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions test/test_functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def test_scale_channel():


class TestRotate:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a new black thing??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are pinning the version

- black == 22.3.0

so let's hope this was just a fluke on my side. I'll revert these.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It indeed comes from a newer black version that I have on my system. Since the removed blank lines don't conflict with the "old" style, it was not automatically reverted by running the pre-commit hook. I opened #7680 to upgrade our linters.

ALL_DTYPES = [None, torch.float32, torch.float64, torch.float16]
scripted_rotate = torch.jit.script(F.rotate)
IMG_W = 26
Expand Down Expand Up @@ -153,7 +152,6 @@ def test_rotate_interpolation_type(self):


class TestAffine:

ALL_DTYPES = [None, torch.float32, torch.float64, torch.float16]
scripted_affine = torch.jit.script(F.affine)

Expand Down Expand Up @@ -407,7 +405,6 @@ def _get_data_dims_and_points_for_perspective():
)
@pytest.mark.parametrize("fn", [F.perspective, torch.jit.script(F.perspective)])
def test_perspective_pil_vs_tensor(device, dims_and_points, dt, fill, fn):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -439,7 +436,6 @@ def test_perspective_pil_vs_tensor(device, dims_and_points, dt, fill, fn):
@pytest.mark.parametrize("dims_and_points", _get_data_dims_and_points_for_perspective())
@pytest.mark.parametrize("dt", [None, torch.float32, torch.float64, torch.float16])
def test_perspective_batch(device, dims_and_points, dt):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -491,7 +487,6 @@ def test_perspective_interpolation_type():
@pytest.mark.parametrize("max_size", [None, 34, 40, 1000])
@pytest.mark.parametrize("interpolation", [BILINEAR, BICUBIC, NEAREST, NEAREST_EXACT])
def test_resize(device, dt, size, max_size, interpolation):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -541,7 +536,6 @@ def test_resize(device, dt, size, max_size, interpolation):

@pytest.mark.parametrize("device", cpu_and_gpu())
def test_resize_asserts(device):

tensor, pil_img = _create_data(26, 36, device=device)

res1 = F.resize(tensor, size=32, interpolation=PIL.Image.BILINEAR)
Expand All @@ -561,7 +555,6 @@ def test_resize_asserts(device):
@pytest.mark.parametrize("size", [[96, 72], [96, 420], [420, 72]])
@pytest.mark.parametrize("interpolation", [BILINEAR, BICUBIC])
def test_resize_antialias(device, dt, size, interpolation):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return
Expand Down Expand Up @@ -609,23 +602,7 @@ def test_resize_antialias(device, dt, size, interpolation):
assert_equal(resized_tensor, resize_result)


@needs_cuda
@pytest.mark.parametrize("interpolation", [BILINEAR, BICUBIC])
def test_assert_resize_antialias(interpolation):

# Checks implementation on very large scales
# and catch TORCH_CHECK inside PyTorch implementation
torch.manual_seed(12)
tensor, _ = _create_data(1000, 1000, device="cuda")

# Error message is not yet updated in pytorch nightly
# with pytest.raises(RuntimeError, match=r"Provided interpolation parameters can not be handled"):
with pytest.raises(RuntimeError, match=r"Too much shared memory required"):
F.resize(tensor, size=(5, 5), interpolation=interpolation, antialias=True)


def test_resize_antialias_default_warning():

img = torch.randint(0, 256, size=(3, 44, 56), dtype=torch.uint8)

match = "The default value of the antialias"
Expand All @@ -641,29 +618,9 @@ def test_resize_antialias_default_warning():
F.resized_crop(img, 0, 0, 10, 10, size=(20, 20), interpolation=NEAREST)


@pytest.mark.parametrize("device", cpu_and_gpu())
@pytest.mark.parametrize("dt", [torch.float32, torch.float64, torch.float16])
@pytest.mark.parametrize("size", [[10, 7], [10, 42], [42, 7]])
@pytest.mark.parametrize("interpolation", [BILINEAR, BICUBIC])
def test_interpolate_antialias_backward(device, dt, size, interpolation):

if dt == torch.float16 and device == "cpu":
# skip float16 on CPU case
return

torch.manual_seed(12)
x = (torch.rand(1, 32, 29, 3, dtype=torch.double, device=device).permute(0, 3, 1, 2).requires_grad_(True),)
resize = partial(F.resize, size=size, interpolation=interpolation, antialias=True)
assert torch.autograd.gradcheck(resize, x, eps=1e-8, atol=1e-6, rtol=1e-6, fast_mode=False)

x = (torch.rand(1, 3, 32, 29, dtype=torch.double, device=device, requires_grad=True),)
assert torch.autograd.gradcheck(resize, x, eps=1e-8, atol=1e-6, rtol=1e-6, fast_mode=False)


def check_functional_vs_PIL_vs_scripted(
fn, fn_pil, fn_t, config, device, dtype, channels=3, tol=2.0 + 1e-10, agg_method="max"
):

script_fn = torch.jit.script(fn)
torch.manual_seed(15)
tensor, pil_img = _create_data(26, 34, channels=channels, device=device)
Expand Down Expand Up @@ -1100,7 +1057,6 @@ def test_crop(device, top, left, height, width):
@pytest.mark.parametrize("sigma", [[0.5, 0.5], (0.5, 0.5), (0.8, 0.8), (1.7, 1.7)])
@pytest.mark.parametrize("fn", [F.gaussian_blur, torch.jit.script(F.gaussian_blur)])
def test_gaussian_blur(device, image_size, dt, ksize, sigma, fn):

# true_cv2_results = {
# # np_img = np.arange(3 * 10 * 12, dtype="uint8").reshape((10, 12, 3))
# # cv2.GaussianBlur(np_img, ksize=(3, 3), sigmaX=0.8)
Expand Down