Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[TFLite FE] Support CUMSUM op (#26673)

Pratik Prajapati90b5dc7e9ad2
diff --git a/src/frontends/tensorflow_common/src/op/cumsum.cpp b/src/frontends/tensorflow_common/src/op/cumsum.cpp
index 9e0343a2529..300eefce732 100644
--- a/src/frontends/tensorflow_common/src/op/cumsum.cpp
+++ b/src/frontends/tensorflow_common/src/op/cumsum.cpp
@@ -18,7 +18,8 @@ namespace tensorflow {
namespace op {
OutputVector translate_cumsum_op(const NodeContext& node) {
- default_op_checks(node, 2, {"Cumsum"}, true);
+ default_op_checks(node, 2, {"Cumsum", "CUMSUM"}, true);
+
auto x = node.get_input(0);
auto axis = node.get_input(1);
auto exclusive = node.get_attribute<bool>("exclusive", false);
diff --git a/src/frontends/tensorflow_lite/src/decoder_flatbuffer.cpp b/src/frontends/tensorflow_lite/src/decoder_flatbuffer.cpp
index 15cba54e54e..35ccc61d773 100644
--- a/src/frontends/tensorflow_lite/src/decoder_flatbuffer.cpp
+++ b/src/frontends/tensorflow_lite/src/decoder_flatbuffer.cpp
@@ -339,6 +339,20 @@ ov::Any DecoderFlatBuffer::get_attribute(const std::string& name) const {
} else {
return {};
}
+ } else if (name == "exclusive" && m_type == "CUMSUM") {
+ bool has_attribute = this->has_attribute(&tflite::CumsumOptions::exclusive);
+ if (has_attribute) {
+ return this->get_attribute(&tflite::CumsumOptions::exclusive);
+ } else {
+ return {};
+ }
+ } else if (name == "reverse" && m_type == "CUMSUM") {
+ bool has_attribute = this->has_attribute(&tflite::CumsumOptions::reverse);
+ if (has_attribute) {
+ return this->get_attribute(&tflite::CumsumOptions::reverse);
+ } else {
+ return {};
+ }
}
const auto opts = m_node_def->custom_options();
diff --git a/src/frontends/tensorflow_lite/src/op_table.cpp b/src/frontends/tensorflow_lite/src/op_table.cpp
index 9adcc0b8db7..a88b8ef1fbc 100644
--- a/src/frontends/tensorflow_lite/src/op_table.cpp
+++ b/src/frontends/tensorflow_lite/src/op_table.cpp
@@ -61,7 +61,7 @@ std::map<std::string, CreatorFunction> get_supported_ops() {
// CONV_3D
// CONV_3D_TRANSPOSE
{"COS", translate_unary<opset10::Cos>},
- // CUMSUM
+ {"CUMSUM", translate_cumsum_op},
// CUSTOM
// DELEGATE
{"DENSIFY", translate_identity_op},
diff --git a/tests/layer_tests/tensorflow_lite_tests/test_tfl_Cumsum.py b/tests/layer_tests/tensorflow_lite_tests/test_tfl_Cumsum.py
new file mode 100644
index 00000000000..297a5540a2d
--- /dev/null
+++ b/tests/layer_tests/tensorflow_lite_tests/test_tfl_Cumsum.py
@@ -0,0 +1,41 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+import numpy as np
+import pytest
+import tensorflow as tf
+
+from common.tflite_layer_test_class import TFLiteLayerTest
+
+test_params = [
+ {'input_shape': [2], 'axis':-1, 'exclusive': False, 'reverse': False},
+ {'input_shape': [2, 3], 'axis':0, 'exclusive': False, 'reverse': False},
+ {'input_shape': [2, 3], 'axis':0, 'exclusive': True, 'reverse': False},
+ {'input_shape': [2, 3], 'axis':0, 'exclusive': False, 'reverse': True},
+]
+
+
+class TestTFLiteCumsum(TFLiteLayerTest):
+ # input_shape - should be an array
+ # axis - array which points on axis for the operation
+ # exclusive - enables exclusive Cumsum
+ # reverse - enables reverse order of Cumsum
+ inputs = ["Input"]
+ outputs = ['Cumsum']
+ allowed_ops = ['CUMSUM']
+
+ def make_model(self, params):
+ tf.compat.v1.reset_default_graph()
+ with tf.compat.v1.Session() as sess:
+ placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.float32),
+ params['input_shape'],
+ name=self.inputs[0])
+ tf.cumsum(placeholder, params['axis'], params['exclusive'],
+ params['reverse'], name=self.outputs[0])
+ net = sess.graph_def
+ return net
+
+ @pytest.mark.parametrize("params", test_params)
+ @pytest.mark.nightly
+ def test_cumsum(self, params, ie_device, precision, temp_dir):
+ self._test(ie_device, precision, temp_dir, params)