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
25 changes: 24 additions & 1 deletion python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def __init__(self, model, subgraph, exp_tab):
'PACK': self.convert_pack,
'LOGISTIC': self.convert_logistic,
'SPLIT': self.convert_split,
'TRANSPOSE': self.convert_transpose
'TRANSPOSE': self.convert_transpose,
'TILE': self.convert_tile
}

def check_unsupported_ops(self):
Expand Down Expand Up @@ -769,6 +770,28 @@ def convert_transpose(self, op):

return out

def convert_tile(self, op):
"""tile implementation."""
try:
from tflite.Operator import Operator
except ImportError:
raise ImportError("The tflite package must be installed")

assert isinstance(op, Operator)
input_tensors = self.get_input_tensors(op)
assert len(input_tensors) == 2, "input tensors length should be 2"
input_tensor = input_tensors[0]
input_tensor_idx = input_tensor.tensor_idx

in_expr = self.get_expr(input_tensor_idx)

# reps (tuple of int) – The number of times repeating the tensor data.
reps = tuple(self.get_tensor_value(input_tensors[1]))

out = _op.tile(in_expr, reps)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment - Maybe directly return _op.tile(...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe current implementation is acceptable. Because all other ops are implemented in this way:

    out = _op.xx()
    # if there are fused activation fn:
    # out = self.convert_fused_activation_function(out, fused_activation_fn)
    return out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is far from a blocking comment :) Consistency is better


return out

def convert_pool2d(self, op, pool_type):
"""pool2d implementation."""
try:
Expand Down
23 changes: 23 additions & 0 deletions tests/python/frontend/tflite/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ def test_forward_transpose():
_test_forward_transpose((2, 3, 4, 5), (3, 0, 1, 2))
_test_forward_transpose((2, 3, 4, 5), ())

#######################################################################
# tile
# ---------


def _test_forward_tile(in_shape, reps, dtype):
data = np.random.uniform(-5, 5, size=in_shape).astype(dtype)

with tf.Graph().as_default():
in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)

out = array_ops.tile(in_data, reps)

compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])


def test_forward_tile():
_test_forward_tile((2, ), (3, ), "int32")
_test_forward_tile((2, 2), (2, 3), "float32")


#######################################################################
# Pooling
Expand Down Expand Up @@ -856,6 +876,9 @@ def test_forward_ssd_mobilenet_v1():
# Transpose
test_forward_transpose()

# Tile
test_forward_tile()

# Transforms
test_forward_concatenation()
test_forward_pad()
Expand Down