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

[TFLITE]FLOOR_MOD & FLOOR_DIV support #4971

Merged
merged 2 commits into from
Mar 2, 2020
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 python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def __init__(self, model, subgraph, exp_tab):
'DETECTION_POSTPROCESS': self.convert_detection_postprocess,
'SQUARE': self.convert_square,
'L2_NORMALIZATION': self.convert_l2_normalization,
'FLOOR_DIV': self.convert_floor_div,
'FLOOR_MOD': self.convert_floor_mod,
}

def check_unsupported_ops(self):
Expand Down Expand Up @@ -1579,6 +1581,20 @@ def convert_pad(self, op):
out = _op.nn.pad(in_expr, pad_width=paddings, pad_value=pad_value)
return out

def convert_floor_div(self, op):
"""Convert TFLite FLOOR_DIV"""
if self.is_quantized(op):
raise tvm.error.OpNotImplemented(
'TFlite quantized FLOOR DIV operator is not supported yet.')
return self._convert_elemwise(_op.floor_divide, op)

def convert_floor_mod(self, op):
"""Convert TFLite FLOOR_MOD"""
if self.is_quantized(op):
raise tvm.error.OpNotImplemented(
'TFlite quantized FLOOR MOD operator is not supported yet.')
return self._convert_elemwise(_op.floor_mod, op)

def convert_mirror_pad(self, op):
"""Convert TFLite MIRROR_PAD"""
try:
Expand Down
19 changes: 19 additions & 0 deletions tests/python/frontend/tflite/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,22 @@ def _test_squared_difference(data):
""" One iteration of squared difference """
return _test_elemwise(math_ops.squared_difference, data)

#######################################################################
# Floor_divide
# ------------

def _test_floor_divide(data):
""" One iteration of floor_div"""
return _test_elemwise(math_ops.floordiv, data)

#######################################################################
# Floor_mod
# ---------

def _test_floor_mod(data):
""" One iteration of floor_mod"""
return _test_elemwise(math_ops.floormod, data)

def _test_forward_elemwise(testop):
""" Elewise"""
testop([np.arange(6.0, dtype=np.float32).reshape((2, 1, 1, 3)),
Expand Down Expand Up @@ -991,6 +1007,9 @@ def test_all_elemwise():
_test_forward_elemwise(_test_less_equal)
_test_forward_elemwise(_test_equal)
_test_forward_elemwise(_test_not_equal)
if package_version.parse(tf.VERSION) >= package_version.parse('1.14.0'):
_test_forward_elemwise(_test_floor_divide)
_test_forward_elemwise(_test_floor_mod)

#######################################################################
# Logical operators
Expand Down