@@ -949,8 +949,8 @@ def test_forward_multi_output():
949
949
tvm .testing .assert_allclose (tf_output [i ], tvm_output [i ], atol = 1e-5 , rtol = 1e-5 )
950
950
951
951
#######################################################################
952
- # Resize Bilinear
953
- # ---------------
952
+ # Resize Bilinear, Nearest_Neighbor
953
+ # ---------------------------------
954
954
955
955
def _test_resize_bilinear (in_shape , to_shape , align_corners ):
956
956
""" One iteration of resize bilinear """
@@ -980,13 +980,31 @@ def _test_resize_bilinear_from_tensor(in_shape, align_corners):
980
980
981
981
compare_tf_with_tvm (data , 'Placeholder:0' , 'ResizeBilinear:0' )
982
982
983
- def test_forward_resize_bilinear ():
984
- """ Resize Bilinear """
983
+
984
+ def _test_resize_nearest_neighbor (in_shape , to_shape ):
985
+ """ One iteration of resize nearest neighbor """
986
+
987
+ data = np .random .uniform (size = in_shape ).astype ('float32' )
988
+ shape_data = np .array (to_shape ).astype ('int32' )
989
+
990
+ with tf .Graph ().as_default ():
991
+ in_data = array_ops .placeholder (shape = data .shape , dtype = data .dtype )
992
+ shape_data = constant_op .constant (
993
+ shape_data , shape = shape_data .shape , dtype = shape_data .dtype )
994
+ tf .image .resize_nearest_neighbor (in_data , shape_data , name = 'resize_nearest_neighbor' )
995
+
996
+ compare_tf_with_tvm (data , 'Placeholder:0' , 'resize_nearest_neighbor:0' )
997
+
998
+
999
+ def test_forward_resize ():
1000
+ """ Resize Bilinear, Nearest_Neighbor """
985
1001
986
1002
_test_resize_bilinear ((4 , 16 , 32 , 32 ), [50 , 50 ], False )
987
1003
_test_resize_bilinear ((6 , 32 , 64 , 64 ), [20 , 20 ], True )
988
1004
_test_resize_bilinear_from_tensor ((4 , 16 , 32 , 32 ), False )
989
1005
_test_resize_bilinear_from_tensor ((6 , 32 , 50 , 50 ), True )
1006
+ _test_resize_nearest_neighbor ((6 , 32 , 64 , 64 ), [20 , 20 ])
1007
+
990
1008
991
1009
#######################################################################
992
1010
# BroadcastTo
@@ -1080,6 +1098,39 @@ def test_forward_crop():
1080
1098
_test_crop ((1 , 224 , 224 , 3 ), 20 , 20 , 120 , 120 )
1081
1099
1082
1100
1101
+ #######################################################################
1102
+ # CropAndResize
1103
+ # -------------
1104
+
1105
+ def _test_forward_crop_and_resize (img_shape , boxes , box_idx , crop_size , method = 'bilinear' , dtype = "float32" ):
1106
+ image = np .random .uniform (0 , 10 , size = img_shape ).astype (dtype )
1107
+ tf .reset_default_graph ()
1108
+ in_data = tf .placeholder (dtype , image .shape , name = "in_data" )
1109
+ tf .image .crop_and_resize (in_data , boxes = boxes , box_ind = box_idx , crop_size = crop_size ,
1110
+ method = method , name = "crop_and_resize" )
1111
+ compare_tf_with_tvm ([image ], ['in_data:0' ], 'crop_and_resize:0' )
1112
+
1113
+ def test_forward_crop_and_resize ():
1114
+ """ CropAndResize """
1115
+ _test_forward_crop_and_resize ([1 , 11 , 11 , 3 ], [[0 , 0 , 1 , 1 ]], [0 ], [5 , 5 ])
1116
+ _test_forward_crop_and_resize ([1 , 11 , 11 , 3 ], [[0 , 0 , .9 , .9 ]], [0 ], [5 , 5 ])
1117
+ _test_forward_crop_and_resize ([1 , 11 , 11 , 3 ], [[.1 , .2 , 1 , 1 ]], [0 ], [5 , 5 ])
1118
+ _test_forward_crop_and_resize ([1 , 21 , 21 , 3 ], [[.2 , .3 , .7 , .9 ]], [0 ], [3 , 4 ])
1119
+ _test_forward_crop_and_resize ([1 , 106 , 106 , 3 ], [[0.2 , 0.4 , 0.8 , 0.8 ]], [0 ], [3 , 3 ])
1120
+ _test_forward_crop_and_resize ([10 , 11 , 11 , 3 ],
1121
+ [[0 , 0 , 0.9 , 0.9 ], [0.2 , 0.2 , 0.8 , 0.8 ]],
1122
+ [0 , 1 ],
1123
+ [5 , 5 ])
1124
+ _test_forward_crop_and_resize ([3 , 11 , 11 , 3 ],
1125
+ [[0 , 0 , 0.9 , 0.9 ], [0.2 , 0.2 , 0.8 , 0.8 ],[0 , 0 , 1 , 1 ]],
1126
+ [0 , 1 , 2 ],
1127
+ [3 , 3 ])
1128
+ _test_forward_crop_and_resize ([3 , 11 , 11 , 3 ],
1129
+ [[0 , 0 , 1 , 0.8 ], [0 , 0 , 0.9 , 0.9 ], [0 , 0 , 1 , 0.8 ]],
1130
+ [2 , 1 , 0 ],
1131
+ [3 , 3 ])
1132
+
1133
+
1083
1134
#######################################################################
1084
1135
# LSTM
1085
1136
# ----
@@ -1979,10 +2030,11 @@ def test_placeholder():
1979
2030
test_forward_depthtospace ()
1980
2031
test_forward_squeeze ()
1981
2032
test_forward_pack ()
1982
- test_forward_resize_bilinear ()
1983
2033
test_forward_broadcast_to ()
1984
2034
test_forward_fill ()
1985
2035
test_forward_crop ()
2036
+ test_forward_resize ()
2037
+ test_forward_crop_and_resize ()
1986
2038
test_forward_pad ()
1987
2039
test_forward_unpack ()
1988
2040
test_forward_gather ()
0 commit comments