Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LOGISTIC operator to relay tflite frontend #3313

Merged
merged 1 commit into from
Jun 11, 2019
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
18 changes: 18 additions & 0 deletions python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, model, subgraph, exp_tab):
'MUL': self.convert_mul,
'FULLY_CONNECTED': self.convert_fully_connected,
'PAD': self.convert_pad,
'LOGISTIC': self.convert_logistic,
}

def check_unsupported_ops(self):
Expand Down Expand Up @@ -218,6 +219,23 @@ def convert_reshape(self, op):

return out

def convert_logistic(self, op):
"""Convert TFLite LOGISTIC"""
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) == 1, "input tensors length should be 1"

input_tensor = input_tensors[0]
in_expr = self.get_expr(input_tensor.tensor_idx)

out = _op.sigmoid(in_expr)
return out

def convert_softmax(self, op):
"""Convert TFLite softmax"""
try:
Expand Down
17 changes: 17 additions & 0 deletions tests/python/frontend/tflite/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,22 @@ def test_forward_pad():
np.array([[1, 1], [2, 2]], dtype=np.int32)])


#######################################################################
# Logistic
# --------

def _test_logistic(data):
""" One iteration of LOGISTIC """
with tf.Graph().as_default():
in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
out = math_ops.sigmoid(in_data)
compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])

def test_forward_logistic():
""" LOGISTIC """
_test_logistic(np.arange(6.0, dtype=np.float32).reshape((1, 6)))


#######################################################################
# Softmax
# -------
Expand Down Expand Up @@ -563,6 +579,7 @@ def test_forward_inception_v4_net():

# NN
test_forward_convolution()
test_forward_logistic()
test_forward_pooling()
test_forward_softmax()
test_forward_fully_connected()
Expand Down