This is an automated email from the ASF dual-hosted git repository. zhaowu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
The following commit(s) were added to refs/heads/master by this push: new a950536 [TFLITE][FRONTEND]Reduce_any op parsing support (#4926) a950536 is described below commit a9505365fc128000ff11cba349147f7eeefcb067 Author: Samuel <siju.sam...@huawei.com> AuthorDate: Thu Mar 12 12:41:37 2020 +0530 [TFLITE][FRONTEND]Reduce_any op parsing support (#4926) * [TFLITE][FRONTEND]Reduce_any op parsing support * Testcase check added to run in tf version above 1.14.0 & review comments * Review comment, checked updated to 1.15 --- python/tvm/relay/frontend/tflite.py | 4 ++++ tests/python/frontend/tflite/test_forward.py | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/python/tvm/relay/frontend/tflite.py b/python/tvm/relay/frontend/tflite.py index 6faf8d9..b4891c3 100644 --- a/python/tvm/relay/frontend/tflite.py +++ b/python/tvm/relay/frontend/tflite.py @@ -102,6 +102,7 @@ class OperatorConverter(object): 'PAD': self.convert_pad, 'POW': self.convert_pow, 'PRELU': self.convert_prelu, + 'REDUCE_ANY': self._convert_reduce_any, 'REDUCE_MAX': self._convert_reduce_max, 'REDUCE_MIN': self._convert_reduce_min, 'REDUCE_PROD': self._convert_reduce_prod, @@ -1088,6 +1089,9 @@ class OperatorConverter(object): def _convert_reduce_sum(self, op): return self._convert_reduce(_op.reduce.sum, op) + def _convert_reduce_any(self, op): + return self._convert_reduce(_op.reduce.any, op) + def convert_fully_connected(self, op): """Convert TFLite fully connected""" try: diff --git a/tests/python/frontend/tflite/test_forward.py b/tests/python/frontend/tflite/test_forward.py index cde8a74..0d76cf2 100644 --- a/tests/python/frontend/tflite/test_forward.py +++ b/tests/python/frontend/tflite/test_forward.py @@ -1154,11 +1154,24 @@ def _test_reduce_sum(data, keep_dims=None): """ One iteration of reduce_sum """ return _test_reduce(math_ops.reduce_sum, data, keep_dims) +####################################################################### +# Reduce_any +# ---------- + +def _test_reduce_any(data, keep_dims=None): + """ One iteration of reduce_any """ + return _test_reduce(math_ops.reduce_any, data, keep_dims) -def _test_forward_reduce(testop): +def _test_forward_reduce(testop, dtype="float32"): """ Reduce """ - data0 = [np.random.rand(16, 16, 16, 16).astype("float32"), None] - data1 = [np.random.rand(16, 16, 16, 16).astype("float32"), np.array([1, 2], dtype=np.int32)] + if dtype == 'bool': + data0 = [np.random.choice(a=[False, True], size=(16, 16, 16, 16)).astype(dtype), + None] + data1 = [np.random.choice(a=[False, True], size=(16, 16, 16, 16)).astype(dtype), + np.array([1, 2], dtype=np.int32)] + else: + data0 = [np.random.rand(16, 16, 16, 16).astype(dtype), None] + data1 = [np.random.rand(16, 16, 16, 16).astype(dtype), np.array([1, 2], dtype=np.int32)] testop(data0) testop(data0, keep_dims=False) testop(data0, keep_dims=True) @@ -1179,6 +1192,8 @@ def test_all_reduce(): _test_forward_reduce_quantized(_test_reduce_mean) _test_forward_reduce(_test_reduce_prod) _test_forward_reduce(_test_reduce_sum) + if package_version.parse(tf.VERSION) >= package_version.parse('1.15.0'): + _test_forward_reduce(_test_reduce_any, dtype="bool") #######################################################################