@@ -1516,32 +1516,74 @@ def test_forward_reshape():
1516
1516
# ------
1517
1517
1518
1518
1519
- def _test_resize (tf_resize_op , data , align_corners ):
1519
+ def _test_resize (tf_resize_op , images_data , size_data , align_corners , quantized = False ):
1520
1520
""" One iteration of Resize """
1521
-
1522
- assert len (data ) == 2
1523
-
1524
1521
# Test with tensor and constant
1525
1522
with tf .Graph ().as_default ():
1526
- images_tensor = array_ops .placeholder (shape = data [0 ].shape , dtype = data [0 ].dtype , name = "in" )
1527
- size = ops .convert_to_tensor (data [1 ], dtype = data [1 ].dtype )
1528
- out_tensor = tf_resize_op (images = images_tensor , size = size , align_corners = align_corners )
1529
- compare_tflite_with_tvm ([data [0 ]], ["in:0" ], [images_tensor ], [out_tensor ])
1523
+ images_tensor = array_ops .placeholder (shape = images_data .shape , dtype = "float32" , name = "in" )
1524
+ size = ops .convert_to_tensor (size_data , dtype = size_data .dtype )
1525
+
1526
+ if quantized :
1527
+ images_tensor_q = tf .quantization .fake_quant_with_min_max_args (
1528
+ images_tensor , min = - 3 , max = 2 , name = "in"
1529
+ )
1530
+ input_range = {"in" : (- 3 , 2 )}
1531
+ out_tensor = tf_resize_op (
1532
+ images = images_tensor_q , size = size , align_corners = align_corners
1533
+ )
1534
+ out_tensor = tf .quantization .fake_quant_with_min_max_args (
1535
+ out_tensor , min = - 3 , max = 2 , name = "out_tensor"
1536
+ )
1537
+
1538
+ compare_tflite_with_tvm (
1539
+ [images_data ],
1540
+ ["in:0" ],
1541
+ [images_tensor ],
1542
+ [out_tensor ],
1543
+ quantized = True ,
1544
+ input_range = input_range ,
1545
+ )
1546
+ else :
1547
+ out_tensor = tf_resize_op (images = images_tensor , size = size , align_corners = align_corners )
1548
+ compare_tflite_with_tvm ([images_data ], ["in:0" ], [images_tensor ], [out_tensor ])
1530
1549
1531
1550
1532
1551
def test_all_resize ():
1533
1552
""" Resize """
1534
- data = [np .random .rand (1 , 16 , 16 , 3 ).astype ("float32" ), np .array ([8 , 8 ], dtype = np .int32 )]
1553
+ images_data = np .random .uniform (0 , 255 , (1 , 16 , 16 , 3 ))
1554
+ images_data_float32 = images_data .astype (np .float32 )
1555
+ images_data_uint8 = images_data .astype (np .uint8 )
1556
+ size_data = np .array ([8 , 8 ]).astype ("int32" )
1535
1557
### RESIZE_BILINEAR
1536
- _test_resize (tf .image .resize_bilinear , data , align_corners = False )
1537
- _test_resize (tf .image .resize_bilinear , data , align_corners = True )
1558
+ _test_resize (
1559
+ tf .image .resize_bilinear ,
1560
+ images_data_float32 ,
1561
+ size_data ,
1562
+ align_corners = False ,
1563
+ quantized = False ,
1564
+ )
1565
+ _test_resize (
1566
+ tf .image .resize_bilinear ,
1567
+ images_data_float32 ,
1568
+ size_data ,
1569
+ align_corners = True ,
1570
+ quantized = False ,
1571
+ )
1572
+ _test_resize (
1573
+ tf .image .resize_bilinear , images_data_uint8 , size_data , align_corners = False , quantized = True
1574
+ )
1575
+ _test_resize (
1576
+ tf .image .resize_bilinear , images_data_uint8 , size_data , align_corners = True , quantized = True
1577
+ )
1538
1578
### RESIZE_NEAREST_NEIGHBOR (was added in v1.13)
1539
1579
# According to topi resize.h
1540
1580
# Align corners not supported for nearest neighbour
1541
1581
from tflite .BuiltinOperator import BuiltinOperator
1542
1582
1543
1583
if "RESIZE_NEAREST_NEIGHBOR" in dir (BuiltinOperator ()):
1544
- _test_resize (tf .image .resize_nearest_neighbor , data , align_corners = False )
1584
+ _test_resize (
1585
+ tf .image .resize_nearest_neighbor , images_data_float32 , size_data , align_corners = False
1586
+ )
1545
1587
1546
1588
1547
1589
#######################################################################
0 commit comments