14
14
cpu_and_gpu ,
15
15
assert_equal ,
16
16
)
17
+ from PIL import Image
17
18
from torchvision import transforms as T
18
19
from torchvision .transforms import InterpolationMode
19
20
from torchvision .transforms import functional as F
21
+ from torchvision .transforms .autoaugment import _apply_op
20
22
21
23
NEAREST , BILINEAR , BICUBIC = InterpolationMode .NEAREST , InterpolationMode .BILINEAR , InterpolationMode .BICUBIC
22
24
@@ -732,10 +734,6 @@ def test_autoaugment__op_apply_shear(interpolation, mode):
732
734
# to official CIFAR10 autoaugment implementation:
733
735
# https://github.com/tensorflow/models/blob/885fda091c46c59d6c7bb5c7e760935eacc229da/
734
736
# research/autoaugment/augmentation_transforms.py#L273-L290
735
- import math
736
-
737
- from PIL import Image
738
-
739
737
image_size = 32
740
738
741
739
def shear (pil_img , level , mode , resample ):
@@ -745,8 +743,6 @@ def shear(pil_img, level, mode, resample):
745
743
matrix = (1 , 0 , 0 , level , 1 , 0 )
746
744
return pil_img .transform ((image_size , image_size ), Image .AFFINE , matrix , resample = resample )
747
745
748
- from torchvision .transforms .autoaugment import _apply_op
749
-
750
746
t_img , pil_img = _create_data (image_size , image_size )
751
747
752
748
resample_pil = {
@@ -757,9 +753,8 @@ def shear(pil_img, level, mode, resample):
757
753
level = 0.3
758
754
expected_out = shear (pil_img , level , mode = mode , resample = resample_pil )
759
755
760
- arc_level = math .atan (level )
761
756
# Check pil output vs expected pil
762
- out = _apply_op (pil_img , op_name = f"Shear{ mode } " , magnitude = arc_level , interpolation = interpolation , fill = 0 )
757
+ out = _apply_op (pil_img , op_name = f"Shear{ mode } " , magnitude = level , interpolation = interpolation , fill = 0 )
763
758
assert out == expected_out
764
759
765
760
if interpolation == F .InterpolationMode .BILINEAR :
@@ -771,7 +766,7 @@ def shear(pil_img, level, mode, resample):
771
766
return
772
767
773
768
# Check tensor output vs expected pil
774
- out = _apply_op (t_img , op_name = f"Shear{ mode } " , magnitude = arc_level , interpolation = interpolation , fill = 0 )
769
+ out = _apply_op (t_img , op_name = f"Shear{ mode } " , magnitude = level , interpolation = interpolation , fill = 0 )
775
770
_assert_approx_equal_tensor_to_pil (out , expected_out )
776
771
777
772
0 commit comments