1313import torchvision .transforms .functional as F
1414from PIL import Image
1515from torch ._utils_internal import get_file_path_2
16+ from torchvision .utils import _Image_fromarray
1617
1718try :
1819 import accimage
@@ -654,7 +655,7 @@ def test_1_channel_float_tensor_to_pil_image(self):
654655 img_F_mode = transforms .ToPILImage (mode = "F" )(img_data )
655656 assert img_F_mode .mode == "F"
656657 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 )
658659 )
659660
660661 @pytest .mark .parametrize ("with_mode" , [False , True ])
@@ -895,7 +896,7 @@ def test_adjust_brightness():
895896 x_shape = [2 , 2 , 3 ]
896897 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
897898 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" )
899900
900901 # test 0
901902 y_pil = F .adjust_brightness (x_pil , 1 )
@@ -921,7 +922,7 @@ def test_adjust_contrast():
921922 x_shape = [2 , 2 , 3 ]
922923 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
923924 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" )
925926
926927 # test 0
927928 y_pil = F .adjust_contrast (x_pil , 1 )
@@ -947,7 +948,7 @@ def test_adjust_hue():
947948 x_shape = [2 , 2 , 3 ]
948949 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
949950 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" )
951952
952953 with pytest .raises (ValueError ):
953954 F .adjust_hue (x_pil , - 0.7 )
@@ -1029,7 +1030,7 @@ def test_adjust_sharpness():
10291030 117 ,
10301031 ]
10311032 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" )
10331034
10341035 # test 0
10351036 y_pil = F .adjust_sharpness (x_pil , 1 )
@@ -1152,7 +1153,7 @@ def test_adjust_sharpness():
11521153 x_shape = [2 , 2 , 3 ]
11531154 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
11541155 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" )
11561157 x_th = torch .tensor (x_np .transpose (2 , 0 , 1 ))
11571158 y_pil = F .adjust_sharpness (x_pil , 2 )
11581159 y_np = np .array (y_pil ).transpose (2 , 0 , 1 )
@@ -1164,7 +1165,7 @@ def test_adjust_gamma():
11641165 x_shape = [2 , 2 , 3 ]
11651166 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
11661167 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" )
11681169
11691170 # test 0
11701171 y_pil = F .adjust_gamma (x_pil , 1 )
@@ -1190,7 +1191,7 @@ def test_adjusts_L_mode():
11901191 x_shape = [2 , 2 , 3 ]
11911192 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
11921193 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" )
11941195
11951196 x_l = x_rgb .convert ("L" )
11961197 assert F .adjust_brightness (x_l , 2 ).mode == "L"
@@ -1320,7 +1321,7 @@ def test_to_grayscale():
13201321 x_shape = [2 , 2 , 3 ]
13211322 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
13221323 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" )
13241325 x_pil_2 = x_pil .convert ("L" )
13251326 gray_np = np .array (x_pil_2 )
13261327
@@ -1769,7 +1770,7 @@ def test_color_jitter():
17691770 x_shape = [2 , 2 , 3 ]
17701771 x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
17711772 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" )
17731774 x_pil_2 = x_pil .convert ("L" )
17741775
17751776 for _ in range (10 ):
0 commit comments