Skip to content

Commit

Permalink
[TFLITE]FLOOR_MOD & FLOOR_DIV support (apache#4971)
Browse files Browse the repository at this point in the history
* TFLite Floor_div & floor_mod parsing code

* Review comment updated
  • Loading branch information
siju-samuel authored and zhiics committed Apr 17, 2020
1 parent 8027b6a commit 960d259
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit 960d259

Please sign in to comment.