[TF FE] Fix TopK translator and add test to the pre-commit (#13971)
Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com> Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>
This commit is contained in:
parent
bbd221e6d3
commit
3b7a5c691d
@ -25,7 +25,7 @@ OutputVector translate_top_k_base_op(const NodeContext& node, const ov::Output<o
|
||||
sorted ? TopK::SortType::SORT_VALUES : TopK::SortType::SORT_INDICES,
|
||||
ov::element::i32);
|
||||
set_node_name(node.get_name(), top_k);
|
||||
return {top_k};
|
||||
return top_k->outputs();
|
||||
}
|
||||
OutputVector translate_top_k_op(const NodeContext& node) {
|
||||
// retrieve k attribute
|
||||
|
54
tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py
Normal file
54
tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright (C) 2018-2022 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 TestTopKV2(CommonTFLayerTest):
|
||||
def _prepare_input(self, inputs_info):
|
||||
# generate elements so that the input tensor may contain repeating elements
|
||||
assert 'input' in inputs_info, "Test error: inputs_info must contain `input`"
|
||||
x_shape = inputs_info['input']
|
||||
inputs_data = {}
|
||||
inputs_data['input'] = np.random.randint(-10, 10, x_shape)
|
||||
return inputs_data
|
||||
|
||||
def create_topk_v2_net(self, input_shape, input_type, k, sorted, is_first_output, is_second_output):
|
||||
tf.compat.v1.reset_default_graph()
|
||||
with tf.compat.v1.Session() as sess:
|
||||
input = tf.compat.v1.placeholder(input_type, input_shape, 'input')
|
||||
k = tf.constant(k, dtype=tf.int32, shape=[])
|
||||
topk = tf.raw_ops.TopKV2(input=input, k=k, sorted=sorted)
|
||||
if is_first_output:
|
||||
tf.identity(topk[0], name='topk_values')
|
||||
if is_second_output:
|
||||
tf.identity(topk[1], name='unique_indices')
|
||||
tf.compat.v1.global_variables_initializer()
|
||||
tf_net = sess.graph_def
|
||||
|
||||
ref_net = None
|
||||
return tf_net, None
|
||||
|
||||
test_basic = [
|
||||
dict(input_shape=[10], input_type=tf.float32, k=5, sorted=True, is_first_output=True, is_second_output=False),
|
||||
dict(input_shape=[2, 3, 10], input_type=tf.int32, k=10, sorted=True, is_first_output=True,
|
||||
is_second_output=False),
|
||||
# Currently, OpenVINO TopK supports only TensorFlow TopK with sorted=True and the first output
|
||||
# For other cases, we need to introduce new version of TopK in OpenVINO opset due to multiple misalignments
|
||||
# described in 88024
|
||||
pytest.param(dict(input_shape=[4, 12], input_type=tf.float32, k=10, sorted=True, is_first_output=True,
|
||||
is_second_output=True), marks=pytest.mark.xfail(reason="88024")),
|
||||
pytest.param(dict(input_shape=[5, 10], input_type=tf.int32, k=8, sorted=False, is_first_output=True,
|
||||
is_second_output=True), marks=pytest.mark.xfail(reason="88024")),
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("params", test_basic)
|
||||
@pytest.mark.precommit_tf_fe
|
||||
def test_topk_v2_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend,
|
||||
use_old_api):
|
||||
self._test(*self.create_topk_v2_net(**params),
|
||||
ie_device, precision, ir_version, temp_dir=temp_dir,
|
||||
use_new_frontend=use_new_frontend, use_old_api=use_old_api)
|
Loading…
Reference in New Issue
Block a user