@@ -969,8 +969,8 @@ def test_forward_multi_output():
969
969
tvm .testing .assert_allclose (tf_output [i ], tvm_output [i ], atol = 1e-5 , rtol = 1e-5 )
970
970
971
971
#######################################################################
972
- # Resize Bilinear
973
- # ---------------
972
+ # Resize Bilinear, Nearest_Neighbor
973
+ # ---------------------------------
974
974
975
975
def _test_resize_bilinear (in_shape , to_shape , align_corners ):
976
976
""" One iteration of resize bilinear """
@@ -1000,13 +1000,31 @@ def _test_resize_bilinear_from_tensor(in_shape, align_corners):
1000
1000
1001
1001
compare_tf_with_tvm (data , 'Placeholder:0' , 'ResizeBilinear:0' )
1002
1002
1003
- def test_forward_resize_bilinear ():
1004
- """ Resize Bilinear """
1003
+
1004
+ def _test_resize_nearest_neighbor (in_shape , to_shape ):
1005
+ """ One iteration of resize nearest neighbor """
1006
+
1007
+ data = np .random .uniform (size = in_shape ).astype ('float32' )
1008
+ shape_data = np .array (to_shape ).astype ('int32' )
1009
+
1010
+ with tf .Graph ().as_default ():
1011
+ in_data = array_ops .placeholder (shape = data .shape , dtype = data .dtype )
1012
+ shape_data = constant_op .constant (
1013
+ shape_data , shape = shape_data .shape , dtype = shape_data .dtype )
1014
+ tf .image .resize_nearest_neighbor (in_data , shape_data , name = 'resize_nearest_neighbor' )
1015
+
1016
+ compare_tf_with_tvm (data , 'Placeholder:0' , 'resize_nearest_neighbor:0' )
1017
+
1018
+
1019
+ def test_forward_resize ():
1020
+ """ Resize Bilinear, Nearest_Neighbor """
1005
1021
1006
1022
_test_resize_bilinear ((4 , 16 , 32 , 32 ), [50 , 50 ], False )
1007
1023
_test_resize_bilinear ((6 , 32 , 64 , 64 ), [20 , 20 ], True )
1008
1024
_test_resize_bilinear_from_tensor ((4 , 16 , 32 , 32 ), False )
1009
1025
_test_resize_bilinear_from_tensor ((6 , 32 , 50 , 50 ), True )
1026
+ _test_resize_nearest_neighbor ((6 , 32 , 64 , 64 ), [20 , 20 ])
1027
+
1010
1028
1011
1029
#######################################################################
1012
1030
# BroadcastTo
@@ -1100,6 +1118,37 @@ def test_forward_crop():
1100
1118
_test_crop ((1 , 224 , 224 , 3 ), 20 , 20 , 120 , 120 )
1101
1119
1102
1120
1121
+ #######################################################################
1122
+ # CropAndResize
1123
+ # -------------
1124
+
1125
+ def _test_forward_crop_and_resize (img_shape , boxes , box_idx , crop_size , method = 'bilinear' , dtype = "float32" ):
1126
+ image = np .random .uniform (0 , 10 , size = img_shape ).astype (dtype )
1127
+ tf .reset_default_graph ()
1128
+ in_data = tf .placeholder (dtype , image .shape , name = "in_data" )
1129
+ tf .image .crop_and_resize (in_data , boxes = boxes , box_ind = box_idx , crop_size = crop_size ,
1130
+ method = method , name = "crop_and_resize" )
1131
+ compare_tf_with_tvm ([image ], ['in_data:0' ], 'crop_and_resize:0' )
1132
+
1133
+ def test_forward_crop_and_resize ():
1134
+ """ CropAndResize """
1135
+ _test_forward_crop_and_resize ([1 , 11 , 11 , 3 ], [[0 , 0 , 1 , 1 ]],
1136
+ [0 ], [5 , 5 ])
1137
+ _test_forward_crop_and_resize ([1 , 11 , 11 , 3 ], [[0 , 0 , .9 , .9 ]],
1138
+ [0 ], [5 , 5 ])
1139
+ _test_forward_crop_and_resize ([1 , 11 , 11 , 3 ], [[.1 , .2 , 1 , 1 ]],
1140
+ [0 ], [5 , 5 ])
1141
+ _test_forward_crop_and_resize ([1 , 21 , 21 , 3 ], [[.2 , .3 , .7 , .9 ]],
1142
+ [0 ], [3 , 4 ])
1143
+ _test_forward_crop_and_resize ([10 , 11 , 11 , 3 ],
1144
+ [[0 , 0 , 0.9 , 0.9 ], [0.2 , 0.2 , 0.8 , 0.8 ]],
1145
+ [0 , 1 ], [5 , 5 ])
1146
+ _test_forward_crop_and_resize ([3 , 11 , 11 , 3 ],
1147
+ [[0 , 0 , 0.9 , 0.9 ], [0.2 , 0.2 , 0.8 , 0.8 ], [0 , 0 , 1 , 1 ]],
1148
+ [0 , 1 , 2 ], [3 , 3 ])
1149
+ _test_forward_crop_and_resize ([1 , 16 , 16 , 3 ], [[0.2 , 0.4 , 0.8 , 0.8 ]], [0 ], [3 , 3 ])
1150
+
1151
+
1103
1152
#######################################################################
1104
1153
# LSTM
1105
1154
# ----
@@ -1989,10 +2038,11 @@ def test_placeholder():
1989
2038
test_forward_depthtospace ()
1990
2039
test_forward_squeeze ()
1991
2040
test_forward_pack ()
1992
- test_forward_resize_bilinear ()
1993
2041
test_forward_broadcast_to ()
1994
2042
test_forward_fill ()
1995
2043
test_forward_crop ()
2044
+ test_forward_resize ()
2045
+ test_forward_crop_and_resize ()
1996
2046
test_forward_pad ()
1997
2047
test_forward_unpack ()
1998
2048
test_forward_gather ()
0 commit comments