Commit 260d660a by Ina Dobreva Committed by Yao Wang

Add parses support for zeros_like tflite operator (#4042)

The tensorflow zeros_like operation provided in array_ops.py produces directly a tensor with zeros
without a graph, using only the shape and type of the input. This imposes the use of gen_array_ops.py
that produces both a tensor and a graph so a comparison between tflite and tvm can be done.
parent 3d9b1739
......@@ -75,6 +75,7 @@ class OperatorConverter(object):
'MAXIMUM': self.convert_maximum,
'MINIMUM': self.convert_minimum,
'GREATER': self.convert_greater,
'ZEROS_LIKE': self.convert_zeros_like,
'REDUCE_MIN': self._convert_reduce_min,
'REDUCE_MAX': self._convert_reduce_max,
'MEAN': self._convert_reduce_mean,
......@@ -478,6 +479,23 @@ class OperatorConverter(object):
def convert_greater(self, op):
return self._convert_elemwise(_op.greater, op)
def convert_zeros_like(self, op):
"""Convert TFLite ZEROS LIKE"""
try:
from tflite.Operator import Operator
except ImportError:
raise ImportError("The tflite package must be installed")
assert isinstance(op, Operator)
input_tensors = self.get_input_tensors(op)
assert len(input_tensors) == 1, "input tensors length should be 1"
input_tensor = input_tensors[0]
in_expr = self.get_expr(input_tensor.tensor_idx)
out = _op.zeros_like(in_expr)
return out
def _convert_reduce(self, relay_op, op):
"""Generic method to Convert TFLite MEAN operators"""
try:
......
......@@ -31,6 +31,7 @@ from tensorflow.python.framework import ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import nn_ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import gen_array_ops
from tensorflow.python.ops import variables
try:
from tensorflow import lite as interpreter_wrapper
......@@ -633,6 +634,21 @@ def test_all_elemwise():
_test_forward_elemwise(_test_greater)
#######################################################################
# Zeros like
# --------
def _test_zeros_like(data):
""" One iteration of ZEROS LIKE """
with tf.Graph().as_default():
in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
out = gen_array_ops.zeros_like(in_data)
compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
def test_forward_zeros_like():
""" ZEROS LIKE """
_test_zeros_like(np.arange(6.0, dtype=np.float32).reshape((1, 6)))
#######################################################################
# Reduce
# ------
......@@ -1020,6 +1036,9 @@ if __name__ == '__main__':
# Elemwise
test_all_elemwise()
# Zeros Like
test_forward_zeros_like()
# Reduce
test_all_reduce()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment