@@ -472,6 +472,50 @@ def test_resize(self):
472472 with self .assertRaisesRegex (ValueError , "max_size = 32 must be strictly greater" ):
473473 F .resize (img , size = 32 , max_size = 32 )
474474
475+ def test_resize_antialias (self ):
476+ script_fn = torch .jit .script (F .resize )
477+ tensor , pil_img = self ._create_data (320 , 290 , device = self .device )
478+
479+ for dt in [None , torch .float32 , torch .float64 , torch .float16 ]:
480+
481+ if dt == torch .float16 and torch .device (self .device ).type == "cpu" :
482+ # skip float16 on CPU case
483+ continue
484+
485+ if dt is not None :
486+ # This is a trivial cast to float of uint8 data to test all cases
487+ tensor = tensor .to (dt )
488+
489+ for size in [[96 , 72 ], ]:
490+ for interpolation in [BILINEAR , ]:
491+ resized_tensor = F .resize (tensor , size = size , interpolation = interpolation , antialias = True )
492+ resized_pil_img = F .resize (pil_img , size = size , interpolation = interpolation )
493+
494+ self .assertEqual (
495+ resized_tensor .size ()[1 :], resized_pil_img .size [::- 1 ],
496+ msg = f"{ size } , { interpolation } , { dt } "
497+ )
498+
499+ resized_tensor_f = resized_tensor
500+ # we need to cast to uint8 to compare with PIL image
501+ if resized_tensor_f .dtype == torch .uint8 :
502+ resized_tensor_f = resized_tensor_f .to (torch .float )
503+
504+ self .approxEqualTensorToPIL (
505+ resized_tensor_f , resized_pil_img , tol = 0.5 , msg = f"{ size } , { interpolation } , { dt } "
506+ )
507+ self .approxEqualTensorToPIL (
508+ resized_tensor_f , resized_pil_img , tol = 1.0 + 1e-5 , agg_method = "max" , msg = f"{ size } , { interpolation } , { dt } "
509+ )
510+
511+ if isinstance (size , int ):
512+ script_size = [size , ]
513+ else :
514+ script_size = size
515+
516+ resize_result = script_fn (tensor , size = script_size , interpolation = interpolation , antialias = True )
517+ self .assertTrue (resized_tensor .equal (resize_result ), msg = "{}, {}" .format (size , interpolation ))
518+
475519 def test_resized_crop (self ):
476520 # test values of F.resized_crop in several cases:
477521 # 1) resize to the same size, crop to the same size => should be identity
0 commit comments