Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions nnvm/python/nnvm/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,21 @@ def _impl(inputs, attr, params):

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 _impl(inputs, attr, params):
try:
Expand Down Expand Up @@ -883,6 +898,7 @@ def _expand_dims_0d_aware(data, attr, axis, num_newaxis=1):
'Sum' : _sum(),
'Square' : _square(),
'Pack' : _pack(),
'Slice' : _slice(),
'LeakyRelu' : AttrCvt('leaky_relu'),
'Relu' : AttrCvt('relu'),
'Reshape' : _reshape(),
Expand Down
18 changes: 18 additions & 0 deletions nnvm/tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,23 @@ def test_forward_resize_bilinear():
_test_resize_bilinear((6, 32, 64, 64), [20, 20], True)


#######################################################################
# 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
# ----
Expand Down Expand Up @@ -1139,6 +1156,7 @@ def test_forward_rel_ops():
test_forward_squeeze()
test_forward_pack()
test_forward_resize_bilinear()
test_forward_crop()
test_forward_pad()
test_forward_gather()
test_forward_stridedslice()
Expand Down