Skip to content

Commit a980357

Browse files
committed
Fixed arc_level -> level as atan is applied internally
1 parent f26233a commit a980357

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

test/test_transforms_tensor.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import os
23

34
import numpy as np
@@ -14,9 +15,11 @@
1415
cpu_and_gpu,
1516
assert_equal,
1617
)
18+
from PIL import Image
1719
from torchvision import transforms as T
1820
from torchvision.transforms import InterpolationMode
1921
from torchvision.transforms import functional as F
22+
from torchvision.transforms.autoaugment import _apply_op
2023

2124
NEAREST, BILINEAR, BICUBIC = InterpolationMode.NEAREST, InterpolationMode.BILINEAR, InterpolationMode.BICUBIC
2225

@@ -732,10 +735,6 @@ def test_autoaugment__op_apply_shear(interpolation, mode):
732735
# to official CIFAR10 autoaugment implementation:
733736
# https://github.com/tensorflow/models/blob/885fda091c46c59d6c7bb5c7e760935eacc229da/
734737
# research/autoaugment/augmentation_transforms.py#L273-L290
735-
import math
736-
737-
from PIL import Image
738-
739738
image_size = 32
740739

741740
def shear(pil_img, level, mode, resample):
@@ -745,8 +744,6 @@ def shear(pil_img, level, mode, resample):
745744
matrix = (1, 0, 0, level, 1, 0)
746745
return pil_img.transform((image_size, image_size), Image.AFFINE, matrix, resample=resample)
747746

748-
from torchvision.transforms.autoaugment import _apply_op
749-
750747
t_img, pil_img = _create_data(image_size, image_size)
751748

752749
resample_pil = {
@@ -757,9 +754,8 @@ def shear(pil_img, level, mode, resample):
757754
level = 0.3
758755
expected_out = shear(pil_img, level, mode=mode, resample=resample_pil)
759756

760-
arc_level = math.atan(level)
761757
# Check pil output vs expected pil
762-
out = _apply_op(pil_img, op_name=f"Shear{mode}", magnitude=arc_level, interpolation=interpolation, fill=0)
758+
out = _apply_op(pil_img, op_name=f"Shear{mode}", magnitude=level, interpolation=interpolation, fill=0)
763759
assert out == expected_out
764760

765761
if interpolation == F.InterpolationMode.BILINEAR:
@@ -771,7 +767,7 @@ def shear(pil_img, level, mode, resample):
771767
return
772768

773769
# Check tensor output vs expected pil
774-
out = _apply_op(t_img, op_name=f"Shear{mode}", magnitude=arc_level, interpolation=interpolation, fill=0)
770+
out = _apply_op(t_img, op_name=f"Shear{mode}", magnitude=level, interpolation=interpolation, fill=0)
775771
_assert_approx_equal_tensor_to_pil(out, expected_out)
776772

777773

0 commit comments

Comments
 (0)