@@ -312,11 +312,12 @@ def adapt_fill(value, *, dtype):
312
312
return value
313
313
314
314
max_value = get_max_value (dtype )
315
+ value_type = float if dtype .is_floating_point else int
315
316
316
317
if isinstance (value , (int , float )):
317
- return type ( value ) (value * max_value )
318
+ return value_type (value * max_value )
318
319
elif isinstance (value , (list , tuple )):
319
- return type (value )(type ( v ) (v * max_value ) for v in value )
320
+ return type (value )(value_type (v * max_value ) for v in value )
320
321
else :
321
322
raise ValueError (f"fill should be an int or float, or a list or tuple of the former, but got '{ value } '." )
322
323
@@ -417,6 +418,10 @@ def affine_bounding_boxes(bounding_boxes):
417
418
)
418
419
419
420
421
+ # turns all warnings into errors for this module
422
+ pytestmark = pytest .mark .filterwarnings ("error" )
423
+
424
+
420
425
class TestResize :
421
426
INPUT_SIZE = (17 , 11 )
422
427
OUTPUT_SIZES = [17 , [17 ], (17 ,), [12 , 13 ], (12 , 13 )]
@@ -2577,15 +2582,19 @@ def test_functional_image_correctness(self, kwargs):
2577
2582
def test_transform (self , param , value , make_input ):
2578
2583
input = make_input (self .INPUT_SIZE )
2579
2584
2580
- kwargs = {param : value }
2581
2585
if param == "fill" :
2582
- # 1. size is required
2583
- # 2. the fill parameter only has an affect if we need padding
2584
- kwargs ["size" ] = [s + 4 for s in self .INPUT_SIZE ]
2585
-
2586
2586
if isinstance (input , tv_tensors .Mask ) and isinstance (value , (tuple , list )):
2587
2587
pytest .skip ("F.pad_mask doesn't support non-scalar fill." )
2588
2588
2589
+ kwargs = dict (
2590
+ # 1. size is required
2591
+ # 2. the fill parameter only has an affect if we need padding
2592
+ size = [s + 4 for s in self .INPUT_SIZE ],
2593
+ fill = adapt_fill (value , dtype = input .dtype if isinstance (input , torch .Tensor ) else torch .uint8 ),
2594
+ )
2595
+ else :
2596
+ kwargs = {param : value }
2597
+
2589
2598
check_transform (
2590
2599
transforms .RandomCrop (** kwargs , pad_if_needed = True ),
2591
2600
input ,
@@ -3478,6 +3487,8 @@ def test_transform_errors(self):
3478
3487
def test_image_correctness (self , padding , padding_mode , fill , fn ):
3479
3488
image = make_image (dtype = torch .uint8 , device = "cpu" )
3480
3489
3490
+ fill = adapt_fill (fill , dtype = torch .uint8 )
3491
+
3481
3492
actual = fn (image , padding = padding , padding_mode = padding_mode , fill = fill )
3482
3493
expected = F .to_image (F .pad (F .to_pil_image (image ), padding = padding , padding_mode = padding_mode , fill = fill ))
3483
3494
0 commit comments