Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TF FE] Support Expm1 operation #27491

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/frontends/tensorflow/docs/supported_ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ A "supported operation" is one that TensorFlow Frontend can convert to the OpenV
| ExperimentalUnbatchDataset | NO | |
| ExperimentalUniqueDataset | NO | |
| Expint | NO | |
| Expm1 | NO | |
| Expm1 | YES | |
| ExtractGlimpse | NO | |
| ExtractGlimpseV2 | NO | |
| ExtractImagePatches | YES | |
Expand Down
1 change: 1 addition & 0 deletions src/frontends/tensorflow/src/op_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const std::map<std::string, CreatorFunction> get_supported_ops() {
{"EmptyTensorList", CreatorFunction(translate_empty_tensor_list_op)},
{"EnsureShape", CreatorFunction(translate_identity_op)},
{"ExpandDims", CreatorFunction(translate_expand_dims_op)},
{"Expm1", CreatorFunction(translate_expm1_op)},
{"ExtractImagePatches", CreatorFunction(translate_extract_image_patches_op)},
{"FakeQuantWithMinMaxVars", CreatorFunction(translate_fake_quant_op)},
{"FakeQuantWithMinMaxVarsPerChannel", CreatorFunction(translate_fake_quant_op)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ OP_CONVERTER(translate_mul_op);
OP_CONVERTER(translate_dynamic_partition_op);
OP_CONVERTER(translate_einsum_op);
OP_CONVERTER(translate_elu_op);
OP_CONVERTER(translate_expm1_op);
OP_CONVERTER(translate_expand_dims_op);
OP_CONVERTER(translate_extract_image_patches_op);
OP_CONVERTER(translate_fake_quant_op);
Expand Down
30 changes: 30 additions & 0 deletions src/frontends/tensorflow_common/src/op/expm1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "common_op_table.hpp"
#include "openvino/op/exp.hpp"
#include "openvino/op/subtract.hpp"
#include "utils.hpp"

using namespace std;
using namespace ov::op;

namespace ov {
namespace frontend {
namespace tensorflow {
namespace op {

OutputVector translate_expm1_op(const NodeContext& node) {
default_op_checks(node, 1, {"Expm1"});
auto input = node.get_input(0);
auto const_one = create_same_type_const_scalar<int>(input, 1);
auto exp = make_shared<v0::Exp>(input);
auto res = make_shared<v1::Subtract>(exp, const_one);
set_node_name(node.get_name(), res);
return {res};
}
} // namespace op
} // namespace tensorflow
} // namespace frontend
} // namespace ov
40 changes: 40 additions & 0 deletions tests/layer_tests/tensorflow_tests/test_tf_Expm1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import pytest
import tensorflow as tf
from common.tf_layer_test_class import CommonTFLayerTest

rng = np.random.default_rng(345345)


class TestExpm1(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'x:0' in inputs_info, "Test error: inputs_info must contain `x`"
x_shape = inputs_info['x:0']
inputs_data = {}
inputs_data['x:0'] = rng.uniform(-2.0, 2.0, x_shape).astype(self.x_type)
return inputs_data

def create_expm1_net(self, x_shape, x_type):
self.x_type = x_type
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
x = tf.compat.v1.placeholder(x_type, x_shape, 'x')
tf.raw_ops.Expm1(x=x)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def

return tf_net, None

@pytest.mark.parametrize('x_shape', [[], [2], [3, 4], [3, 2, 1, 4]])
@pytest.mark.parametrize('x_type', [np.float16, np.float32, np.float64])
@pytest.mark.precommit
@pytest.mark.nightly
def test_expm1(self, x_shape, x_type, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
self._test(*self.create_expm1_net(x_shape, x_type),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)
Loading