diff --git a/src/frontends/tensorflow_common/include/common_op_table.hpp b/src/frontends/tensorflow_common/include/common_op_table.hpp index 9d32aa0f780..08bf463807a 100644 --- a/src/frontends/tensorflow_common/include/common_op_table.hpp +++ b/src/frontends/tensorflow_common/include/common_op_table.hpp @@ -84,6 +84,7 @@ OP_CONVERTER(translate_gather_op); OP_CONVERTER(translate_gather_v2_op); OP_CONVERTER(translate_gather_nd_op); OP_CONVERTER(translate_gather_tree_op); +OP_CONVERTER(translate_gelu_op); OP_CONVERTER(translate_identity_op); OP_CONVERTER(translate_identity_n_op); OP_CONVERTER(translate_ifft_op); diff --git a/src/frontends/tensorflow_common/src/op/gelu.cpp b/src/frontends/tensorflow_common/src/op/gelu.cpp new file mode 100644 index 00000000000..7ae644f0f44 --- /dev/null +++ b/src/frontends/tensorflow_common/src/op/gelu.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/gelu.hpp" + +#include "common_op_table.hpp" + +using namespace std; +using namespace ov; +using namespace ov::op; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { + +OutputVector translate_gelu_op(const NodeContext& node) { + default_op_checks(node, 1, {"GELU"}); + auto input = node.get_input(0); + auto approximate = node.get_attribute("approximate"); + const auto mode = (approximate == true) ? ov::op::GeluApproximationMode::TANH : ov::op::GeluApproximationMode::ERF; + auto res = make_shared(input, mode); + set_node_name(node.get_name(), res); + return res->outputs(); +}; + +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_lite/src/op/gelu.cpp b/src/frontends/tensorflow_lite/src/op/gelu.cpp new file mode 100644 index 00000000000..3ded6cc8082 --- /dev/null +++ b/src/frontends/tensorflow_lite/src/op/gelu.cpp @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "op_translation_utils.hpp" +#include "utils.hpp" + +using namespace std; + +namespace ov { +namespace frontend { +namespace tensorflow_lite { +namespace op { + +OutputVector gelu(const ov::frontend::tensorflow_lite::NodeContext& node) { + const auto& decoder = get_decoder(node); + std::map attrs{ + {"approximate", decoder->get_attribute(&tflite::GeluOptions::approximate)}, + }; + return attribute_helper(node, attrs, ov::frontend::tensorflow::op::translate_gelu_op); +} + +} // namespace op +} // namespace tensorflow_lite +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_lite/src/op_table.cpp b/src/frontends/tensorflow_lite/src/op_table.cpp index aab01caff2b..f85d5dcb708 100644 --- a/src/frontends/tensorflow_lite/src/op_table.cpp +++ b/src/frontends/tensorflow_lite/src/op_table.cpp @@ -86,7 +86,7 @@ std::map get_supported_ops() { {"FULLY_CONNECTED", DEQUANTIZE_INPUTS(fully_connected)}, {"GATHER", DEQUANTIZE_INPUTS(gather)}, {"GATHER_ND", DEQUANTIZE_INPUTS(translate_gather_nd_op)}, - // GELU + {"GELU", DEQUANTIZE_INPUTS(gelu)}, {"GREATER", translate_binary}, {"GREATER_EQUAL", translate_binary}, {"HARD_SWISH", translate_unary}, diff --git a/src/frontends/tensorflow_lite/src/op_table.hpp b/src/frontends/tensorflow_lite/src/op_table.hpp index 385d200dff0..637f39ad827 100644 --- a/src/frontends/tensorflow_lite/src/op_table.hpp +++ b/src/frontends/tensorflow_lite/src/op_table.hpp @@ -39,6 +39,7 @@ TFL_OP_CONVERTER(depthwise_conv2d); TFL_OP_CONVERTER(dequantize); TFL_OP_CONVERTER(fully_connected); TFL_OP_CONVERTER(gather); +TFL_OP_CONVERTER(gelu); TFL_OP_CONVERTER(l2_normalization); TFL_OP_CONVERTER(leaky_relu); TFL_OP_CONVERTER(max_pool_2d); diff --git a/tests/layer_tests/tensorflow2_keras_tests/test_tf2_keras_activation.py b/tests/layer_tests/tensorflow2_keras_tests/test_tf2_keras_activation.py index a5756b248f1..2d8ecaf6f19 100644 --- a/tests/layer_tests/tensorflow2_keras_tests/test_tf2_keras_activation.py +++ b/tests/layer_tests/tensorflow2_keras_tests/test_tf2_keras_activation.py @@ -14,6 +14,7 @@ class TestKerasActivation(CommonTF2LayerTest): # pytest-xdist can't execute the tests in parallel because workers can't compare tests scopes before run # tf.nn. operation have no "==" operation to be compared "elu": tf.nn.elu, + "gelu": tf.nn.gelu, "relu": tf.nn.relu, "sigmoid": tf.nn.sigmoid, "softmax": tf.nn.softmax, @@ -40,6 +41,8 @@ class TestKerasActivation(CommonTF2LayerTest): test_data_float32 = [ dict(activation_func="elu", input_names=["x1"], input_shapes=[[5, 4]], input_type=tf.float32), + dict(activation_func="gelu", input_names=["x1"], input_shapes=[[5, 4]], + input_type=tf.float32), dict(activation_func="relu", input_names=["x1"], input_shapes=[[5, 4, 8]], input_type=tf.float32), dict(activation_func="sigmoid", input_names=["x1"], input_shapes=[[5, 4, 8, 3]],