[TF FE]: Support Rint operation for TensorFlow (#24059)

Closes https://github.com/openvinotoolkit/openvino/issues/24032
### Details:
 - Support Rint operation for TensorFlow.

---------

Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
This commit is contained in:
awayzjj 2024-04-17 18:04:59 +08:00 committed by GitHub
parent f06d19ae28
commit 9331eb54da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 72 additions and 1 deletions

View File

@ -988,7 +988,7 @@ A "supported operation" is one that TensorFlow Frontend can convert to the OpenV
| ReverseV2 | YES | |
| RewriteDataset | NO | |
| RightShift | NO | |
| Rint | NO | |
| Rint | YES | |
| RngReadAndSkip | NO | |
| RngSkip | NO | |
| Roll | YES | |

View File

@ -353,6 +353,7 @@ const std::map<std::string, CreatorFunction> get_supported_ops() {
{"RFFT", CreatorFunction(translate_rfft_op)},
{"RFFT2D", CreatorFunction(translate_rfft_op)},
{"RFFT3D", CreatorFunction(translate_rfft_op)},
{"Rint", CreatorFunction(translate_rint_op)},
{"Roll", CreatorFunction(translate_roll_op)},
{"Round", CreatorFunction(translate_round_op)},
{"Rsqrt", CreatorFunction(translate_rsqrt_op)},

View File

@ -135,6 +135,7 @@ OP_CONVERTER(translate_reverse_op);
OP_CONVERTER(translate_reverse_v2_op);
OP_CONVERTER(translate_reverse_sequence_op);
OP_CONVERTER(translate_rfft_op);
OP_CONVERTER(translate_rint_op);
OP_CONVERTER(translate_roll_op);
OP_CONVERTER(translate_round_op);
OP_CONVERTER(translate_rsqrt_op);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "common_op_table.hpp"
#include "openvino/op/round.hpp"
using namespace std;
using namespace ov::op;
namespace ov {
namespace frontend {
namespace tensorflow {
namespace op {
OutputVector translate_rint_op(const NodeContext& node) {
default_op_checks(node, 1, {"Rint"});
auto input = node.get_input(0);
// using default round mode "half_to_even" in openvino,
// as TF has only that mode
auto round_mode = v5::Round::RoundMode::HALF_TO_EVEN;
auto res = make_shared<v5::Round>(input, round_mode);
set_node_name(node.get_name(), res);
return res->outputs();
}
} // namespace op
} // namespace tensorflow
} // namespace frontend
} // namespace ov

View File

@ -0,0 +1,39 @@
# 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
class TestRint(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'input:0' in inputs_info
inputs_shape = inputs_info['input:0']
inputs_data = {}
rng = np.random.default_rng()
inputs_data['input:0'] = rng.uniform(-5.0, 5.0, inputs_shape).astype(self.input_type)
return inputs_data
def create_tf_rint_net(self, input_shape, input_type):
self.input_type = input_type
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
input = tf.compat.v1.placeholder(input_type, input_shape, 'input')
tf.raw_ops.Rint(x=input)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
ref_net = None
return tf_net, ref_net
@pytest.mark.parametrize("input_shape", [[], [6], [2, 5], [5, 4, 1]])
@pytest.mark.parametrize("input_type", [np.float32, np.float64])
@pytest.mark.precommit
@pytest.mark.nightly
def test_rint_basic(self, input_shape, input_type, ie_device, precision,
ir_version, temp_dir, use_legacy_frontend):
self._test(*self.create_tf_rint_net(input_shape, input_type),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)