11import  os 
22import  pathlib 
33
4+ import  keras 
45import  numpy  as  np 
56import  pytest 
7+ from  absl .testing  import  parameterized 
68from  keras  import  ops 
79
810from  keras_hub .src .layers .preprocessing .image_converter  import  ImageConverter 
@@ -33,11 +35,21 @@ def test_unbatched(self):
3335        self .assertAllClose (outputs [:, :, 1 ], np .ones ((4 , 4 )) *  0.301569 )
3436        self .assertAllClose (outputs [:, :, 2 ], np .ones ((4 , 4 )) *  0.852353 )
3537
36-     def  test_resize_batch (self ):
38+     @parameterized .parameters ( 
39+         (True , False ), 
40+         (False , True ), 
41+     ) 
42+     @pytest .mark .skipif ( 
43+         keras .config .backend () ==  "torch" , 
44+         reason = "disabled until resize is fixed for torch backend" , 
45+     )  # TODO: remove skip after new release with fix of https://github.com/keras-team/keras/pull/20797  
46+     def  test_resize_batch (self , crop_to_aspect_ratio , pad_to_aspect_ratio ):
3747        converter  =  ImageConverter (
3848            image_size = (4 , 4 ),
3949            scale = (1.0  /  255.0 , 0.8  /  255.0 , 1.2  /  255.0 ),
4050            offset = (0.2 , - 0.1 , 0.25 ),
51+             crop_to_aspect_ratio = crop_to_aspect_ratio ,
52+             pad_to_aspect_ratio = pad_to_aspect_ratio ,
4153        )
4254        inputs  =  np .ones ((2 , 10 , 10 , 3 )) *  128 
4355        outputs  =  converter (inputs )
@@ -46,6 +58,15 @@ def test_resize_batch(self):
4658        self .assertAllClose (outputs [:, :, :, 1 ], np .ones ((2 , 4 , 4 )) *  0.301569 )
4759        self .assertAllClose (outputs [:, :, :, 2 ], np .ones ((2 , 4 , 4 )) *  0.852353 )
4860
61+     def  test_pad_and_crop_to_aspect_ratio (self ):
62+         with  self .assertRaisesRegex (ValueError , "Only one of" ):
63+             _  =  ImageConverter (
64+                 image_size = (4 , 4 ),
65+                 scale = 1  /  255.0 ,
66+                 crop_to_aspect_ratio = True ,
67+                 pad_to_aspect_ratio = True ,
68+             )
69+ 
4970    def  test_config (self ):
5071        converter  =  ImageConverter (
5172            image_size = (12 , 20 ),
0 commit comments