13
13
import torchvision .transforms .functional as F
14
14
from PIL import Image
15
15
from torch ._utils_internal import get_file_path_2
16
+ from torchvision .utils import _Image_fromarray
16
17
17
18
try :
18
19
import accimage
@@ -654,7 +655,7 @@ def test_1_channel_float_tensor_to_pil_image(self):
654
655
img_F_mode = transforms .ToPILImage (mode = "F" )(img_data )
655
656
assert img_F_mode .mode == "F"
656
657
torch .testing .assert_close (
657
- np .array (Image . fromarray (img_data .squeeze (0 ).numpy (), mode = "F" )), np .array (img_F_mode )
658
+ np .array (_Image_fromarray (img_data .squeeze (0 ).numpy (), mode = "F" )), np .array (img_F_mode )
658
659
)
659
660
660
661
@pytest .mark .parametrize ("with_mode" , [False , True ])
@@ -895,7 +896,7 @@ def test_adjust_brightness():
895
896
x_shape = [2 , 2 , 3 ]
896
897
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
897
898
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
898
- x_pil = Image . fromarray (x_np , mode = "RGB" )
899
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
899
900
900
901
# test 0
901
902
y_pil = F .adjust_brightness (x_pil , 1 )
@@ -921,7 +922,7 @@ def test_adjust_contrast():
921
922
x_shape = [2 , 2 , 3 ]
922
923
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
923
924
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
924
- x_pil = Image . fromarray (x_np , mode = "RGB" )
925
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
925
926
926
927
# test 0
927
928
y_pil = F .adjust_contrast (x_pil , 1 )
@@ -947,7 +948,7 @@ def test_adjust_hue():
947
948
x_shape = [2 , 2 , 3 ]
948
949
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
949
950
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
950
- x_pil = Image . fromarray (x_np , mode = "RGB" )
951
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
951
952
952
953
with pytest .raises (ValueError ):
953
954
F .adjust_hue (x_pil , - 0.7 )
@@ -1029,7 +1030,7 @@ def test_adjust_sharpness():
1029
1030
117 ,
1030
1031
]
1031
1032
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1032
- x_pil = Image . fromarray (x_np , mode = "RGB" )
1033
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
1033
1034
1034
1035
# test 0
1035
1036
y_pil = F .adjust_sharpness (x_pil , 1 )
@@ -1152,7 +1153,7 @@ def test_adjust_sharpness():
1152
1153
x_shape = [2 , 2 , 3 ]
1153
1154
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
1154
1155
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1155
- x_pil = Image . fromarray (x_np , mode = "RGB" )
1156
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
1156
1157
x_th = torch .tensor (x_np .transpose (2 , 0 , 1 ))
1157
1158
y_pil = F .adjust_sharpness (x_pil , 2 )
1158
1159
y_np = np .array (y_pil ).transpose (2 , 0 , 1 )
@@ -1164,7 +1165,7 @@ def test_adjust_gamma():
1164
1165
x_shape = [2 , 2 , 3 ]
1165
1166
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
1166
1167
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1167
- x_pil = Image . fromarray (x_np , mode = "RGB" )
1168
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
1168
1169
1169
1170
# test 0
1170
1171
y_pil = F .adjust_gamma (x_pil , 1 )
@@ -1190,7 +1191,7 @@ def test_adjusts_L_mode():
1190
1191
x_shape = [2 , 2 , 3 ]
1191
1192
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
1192
1193
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1193
- x_rgb = Image . fromarray (x_np , mode = "RGB" )
1194
+ x_rgb = _Image_fromarray (x_np , mode = "RGB" )
1194
1195
1195
1196
x_l = x_rgb .convert ("L" )
1196
1197
assert F .adjust_brightness (x_l , 2 ).mode == "L"
@@ -1320,7 +1321,7 @@ def test_to_grayscale():
1320
1321
x_shape = [2 , 2 , 3 ]
1321
1322
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
1322
1323
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1323
- x_pil = Image . fromarray (x_np , mode = "RGB" )
1324
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
1324
1325
x_pil_2 = x_pil .convert ("L" )
1325
1326
gray_np = np .array (x_pil_2 )
1326
1327
@@ -1769,7 +1770,7 @@ def test_color_jitter():
1769
1770
x_shape = [2 , 2 , 3 ]
1770
1771
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
1771
1772
x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1772
- x_pil = Image . fromarray (x_np , mode = "RGB" )
1773
+ x_pil = _Image_fromarray (x_np , mode = "RGB" )
1773
1774
x_pil_2 = x_pil .convert ("L" )
1774
1775
1775
1776
for _ in range (10 ):
0 commit comments