Skip to content

Commit

Permalink
TFLite Floor_div & floor_mod parsing code
Browse files Browse the repository at this point in the history
  • Loading branch information
siju-samuel committed Feb 29, 2020
1 parent a449d8b commit 39455f9
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 @@ -122,6 +122,8 @@ def __init__(self, model, subgraph, exp_tab):
'LOGICAL_OR': self.convert_logical_or,
'DETECTION_POSTPROCESS': self.convert_detection_postprocess,
'SQUARE': self.convert_square,
'FLOOR_DIV': self.convert_floor_div,
'FLOOR_MOD': self.convert_floor_mod,
}

def check_unsupported_ops(self):
Expand Down Expand Up @@ -1532,6 +1534,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 @@ -942,6 +942,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 @@ -990,6 +1006,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 39455f9

Please sign in to comment.