Commit 6737739c by Ashutosh Parkhi Committed by Siva

[Tensorflow] Support for Crop (#2285)

fixes

fixes
parent a9bd5593
...@@ -388,6 +388,21 @@ def _pack(): ...@@ -388,6 +388,21 @@ def _pack():
return _impl return _impl
def _slice():
def _impl(inputs, attr, params):
begin = params.pop(inputs[1].list_output_names()[0]).asnumpy().tolist()
size = params.pop(inputs[2].list_output_names()[0]).asnumpy().tolist()
data_shape = attr['_input_shapes'][inputs[0]]
data_dim = len(data_shape)
end = size
for i in range(data_dim):
if size[i] == -1:
end[i] = data_shape[i] - begin[i]
else:
end[i] += begin[i]
return _sym.strided_slice(inputs[0], begin=begin, end=size)
return _impl
def _reshape(): def _reshape():
def _impl(inputs, attr, params): def _impl(inputs, attr, params):
try: try:
...@@ -883,6 +898,7 @@ _convert_map = { ...@@ -883,6 +898,7 @@ _convert_map = {
'Sum' : _sum(), 'Sum' : _sum(),
'Square' : _square(), 'Square' : _square(),
'Pack' : _pack(), 'Pack' : _pack(),
'Slice' : _slice(),
'LeakyRelu' : AttrCvt('leaky_relu'), 'LeakyRelu' : AttrCvt('leaky_relu'),
'Relu' : AttrCvt('relu'), 'Relu' : AttrCvt('relu'),
'Reshape' : _reshape(), 'Reshape' : _reshape(),
......
...@@ -656,6 +656,23 @@ def test_forward_resize_bilinear(): ...@@ -656,6 +656,23 @@ def test_forward_resize_bilinear():
####################################################################### #######################################################################
# Crop to bounding box
# --------------------
def _test_crop(in_shape, off_h, off_w, tar_h, tar_w):
""" Crop to bounding box """
data = np.random.uniform(size=in_shape).astype('float32')
with tf.Graph().as_default():
in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
tf.image.crop_to_bounding_box(in_data, off_h, off_w, tar_h, tar_w)
compare_tf_with_tvm(data, 'Placeholder:0', 'crop_to_bounding_box/Slice:0')
def test_forward_crop():
""" Crop to bounding box """
_test_crop((1, 224, 224, 3), 20, 20, 120, 120)
#######################################################################
# LSTM # LSTM
# ---- # ----
...@@ -1139,6 +1156,7 @@ if __name__ == '__main__': ...@@ -1139,6 +1156,7 @@ if __name__ == '__main__':
test_forward_squeeze() test_forward_squeeze()
test_forward_pack() test_forward_pack()
test_forward_resize_bilinear() test_forward_resize_bilinear()
test_forward_crop()
test_forward_pad() test_forward_pad()
test_forward_gather() test_forward_gather()
test_forward_stridedslice() test_forward_stridedslice()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment