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