From 39455f96ad7e48116ad26aa62cc10d183d35d705 Mon Sep 17 00:00:00 2001 From: Siju Samuel Date: Sat, 29 Feb 2020 10:46:15 +0530 Subject: [PATCH] TFLite Floor_div & floor_mod parsing code --- python/tvm/relay/frontend/tflite.py | 16 ++++++++++++++++ tests/python/frontend/tflite/test_forward.py | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/python/tvm/relay/frontend/tflite.py b/python/tvm/relay/frontend/tflite.py index 3a17083d60acc..1378ce59d9eb6 100644 --- a/python/tvm/relay/frontend/tflite.py +++ b/python/tvm/relay/frontend/tflite.py @@ -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): @@ -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: diff --git a/tests/python/frontend/tflite/test_forward.py b/tests/python/frontend/tflite/test_forward.py index 4a16325e3e407..7ee343dd7b8e8 100644 --- a/tests/python/frontend/tflite/test_forward.py +++ b/tests/python/frontend/tflite/test_forward.py @@ -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)), @@ -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