@@ -1351,32 +1351,74 @@ def test_forward_reshape():
1351
1351
# ------
1352
1352
1353
1353
1354
- def _test_resize (tf_resize_op , data , align_corners ):
1354
+ def _test_resize (tf_resize_op , images_data , size_data , align_corners , quantized = False ):
1355
1355
""" One iteration of Resize """
1356
-
1357
- assert len (data ) == 2
1358
-
1359
1356
# Test with tensor and constant
1360
1357
with tf .Graph ().as_default ():
1361
- images_tensor = array_ops .placeholder (shape = data [0 ].shape , dtype = data [0 ].dtype , name = "in" )
1362
- size = ops .convert_to_tensor (data [1 ], dtype = data [1 ].dtype )
1363
- out_tensor = tf_resize_op (images = images_tensor , size = size , align_corners = align_corners )
1364
- compare_tflite_with_tvm ([data [0 ]], ["in:0" ], [images_tensor ], [out_tensor ])
1358
+ images_tensor = array_ops .placeholder (shape = images_data .shape , dtype = "float32" , name = "in" )
1359
+ size = ops .convert_to_tensor (size_data , dtype = size_data .dtype )
1360
+
1361
+ if quantized :
1362
+ images_tensor_q = tf .quantization .fake_quant_with_min_max_args (
1363
+ images_tensor , min = - 3 , max = 2 , name = "in"
1364
+ )
1365
+ input_range = {"in" : (- 3 , 2 )}
1366
+ out_tensor = tf_resize_op (
1367
+ images = images_tensor_q , size = size , align_corners = align_corners
1368
+ )
1369
+ out_tensor = tf .quantization .fake_quant_with_min_max_args (
1370
+ out_tensor , min = - 3 , max = 2 , name = "out_tensor"
1371
+ )
1372
+
1373
+ compare_tflite_with_tvm (
1374
+ [images_data ],
1375
+ ["in:0" ],
1376
+ [images_tensor ],
1377
+ [out_tensor ],
1378
+ quantized = True ,
1379
+ input_range = input_range ,
1380
+ )
1381
+ else :
1382
+ out_tensor = tf_resize_op (images = images_tensor , size = size , align_corners = align_corners )
1383
+ compare_tflite_with_tvm ([images_data ], ["in:0" ], [images_tensor ], [out_tensor ])
1365
1384
1366
1385
1367
1386
def test_all_resize ():
1368
1387
""" Resize """
1369
- data = [np .random .rand (1 , 16 , 16 , 3 ).astype ("float32" ), np .array ([8 , 8 ], dtype = np .int32 )]
1388
+ images_data = np .random .uniform (0 , 255 , (1 , 16 , 16 , 3 ))
1389
+ images_data_float32 = images_data .astype (np .float32 )
1390
+ images_data_uint8 = images_data .astype (np .uint8 )
1391
+ size_data = np .array ([8 , 8 ]).astype ("int32" )
1370
1392
### RESIZE_BILINEAR
1371
- _test_resize (tf .image .resize_bilinear , data , align_corners = False )
1372
- _test_resize (tf .image .resize_bilinear , data , align_corners = True )
1393
+ _test_resize (
1394
+ tf .image .resize_bilinear ,
1395
+ images_data_float32 ,
1396
+ size_data ,
1397
+ align_corners = False ,
1398
+ quantized = False ,
1399
+ )
1400
+ _test_resize (
1401
+ tf .image .resize_bilinear ,
1402
+ images_data_float32 ,
1403
+ size_data ,
1404
+ align_corners = True ,
1405
+ quantized = False ,
1406
+ )
1407
+ _test_resize (
1408
+ tf .image .resize_bilinear , images_data_uint8 , size_data , align_corners = False , quantized = True
1409
+ )
1410
+ _test_resize (
1411
+ tf .image .resize_bilinear , images_data_uint8 , size_data , align_corners = True , quantized = True
1412
+ )
1373
1413
### RESIZE_NEAREST_NEIGHBOR (was added in v1.13)
1374
1414
# According to topi resize.h
1375
1415
# Align corners not supported for nearest neighbour
1376
1416
from tflite .BuiltinOperator import BuiltinOperator
1377
1417
1378
1418
if "RESIZE_NEAREST_NEIGHBOR" in dir (BuiltinOperator ()):
1379
- _test_resize (tf .image .resize_nearest_neighbor , data , align_corners = False )
1419
+ _test_resize (
1420
+ tf .image .resize_nearest_neighbor , images_data_float32 , size_data , align_corners = False
1421
+ )
1380
1422
1381
1423
1382
1424
#######################################################################
0 commit comments