forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TF Hub][TF FE] Support TensorListLength and TensorListResize operati…
…ons (openvinotoolkit#19390) * [TF Hub][TF FE] Support TensorListLength and TensorListResize operations Signed-off-by: Kazantsev, Roman <[email protected]> * Add test with empty tensor list * remove assert --------- Signed-off-by: Kazantsev, Roman <[email protected]>
- Loading branch information
Showing
5 changed files
with
249 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
tests/layer_tests/tensorflow_tests/test_tf_TensorListLength.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (C) 2018-2023 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 TestTensorListLength(CommonTFLayerTest): | ||
def _prepare_input(self, inputs_info): | ||
assert 'x' in inputs_info | ||
x_shape = inputs_info['x'] | ||
inputs_data = {} | ||
inputs_data['x'] = np.random.randint(-10, 10, x_shape).astype(self.input_type) | ||
return inputs_data | ||
|
||
def create_tensor_list_length(self, input_shape, input_type): | ||
self.input_type = input_type | ||
tf.compat.v1.reset_default_graph() | ||
# Create the graph and model | ||
with tf.compat.v1.Session() as sess: | ||
x = tf.compat.v1.placeholder(input_type, input_shape, 'x') | ||
tensor_list = tf.raw_ops.TensorListFromTensor(tensor=x, | ||
element_shape=tf.constant(input_shape[1:], dtype=tf.int32)) | ||
tf.raw_ops.TensorListLength(input_handle=tensor_list) | ||
tf.compat.v1.global_variables_initializer() | ||
tf_net = sess.graph_def | ||
|
||
return tf_net, None | ||
|
||
test_data_basic = [ | ||
dict(input_shape=[7], input_type=np.float32), | ||
dict(input_shape=[10, 20], input_type=np.float32), | ||
dict(input_shape=[2, 3, 4], input_type=np.int32), | ||
] | ||
|
||
@pytest.mark.parametrize("params", test_data_basic) | ||
@pytest.mark.precommit_tf_fe | ||
@pytest.mark.nightly | ||
def test_tensor_list_length_basic(self, params, ie_device, precision, ir_version, temp_dir, | ||
use_new_frontend, use_old_api): | ||
self._test(*self.create_tensor_list_length(**params), | ||
ie_device, precision, ir_version, temp_dir=temp_dir, | ||
use_new_frontend=use_new_frontend, use_old_api=use_old_api) | ||
|
||
|
||
class TestTensorListLengthEmptyList(CommonTFLayerTest): | ||
def _prepare_input(self, inputs_info): | ||
inputs_data = {} | ||
inputs_data['tensor_list_size'] = np.array([self.tensor_list_size], dtype=np.int32) | ||
return inputs_data | ||
|
||
def create_tensor_list_length_empty_list(self, tensor_list_size, element_shape): | ||
self.tensor_list_size = tensor_list_size | ||
tf.compat.v1.reset_default_graph() | ||
# Create the graph and model | ||
with tf.compat.v1.Session() as sess: | ||
tensor_list_size = tf.compat.v1.placeholder(tf.int32, [1], 'tensor_list_size') | ||
tf_element_shape = tf.constant(element_shape, dtype=tf.int32) | ||
tensor_shape = tf.concat([tensor_list_size, tf_element_shape], 0) | ||
tensor = tf.broadcast_to(tf.constant(0.0, dtype=tf.float32), tensor_shape) | ||
tensor_list = tf.raw_ops.TensorListFromTensor(tensor=tensor, | ||
element_shape=tf_element_shape) | ||
tf.raw_ops.TensorListLength(input_handle=tensor_list) | ||
tf.compat.v1.global_variables_initializer() | ||
tf_net = sess.graph_def | ||
|
||
return tf_net, None | ||
|
||
test_data_tensor_list_length_empty_list = [ | ||
dict(tensor_list_size=0, element_shape=[]), | ||
dict(tensor_list_size=0, element_shape=[2, 3]), | ||
] | ||
|
||
@pytest.mark.parametrize("params", test_data_tensor_list_length_empty_list) | ||
@pytest.mark.precommit_tf_fe | ||
@pytest.mark.nightly | ||
def test_tensor_list_length_empty_list(self, params, ie_device, precision, ir_version, temp_dir, | ||
use_new_frontend, use_old_api): | ||
self._test(*self.create_tensor_list_length_empty_list(**params), | ||
ie_device, precision, ir_version, temp_dir=temp_dir, | ||
use_new_frontend=use_new_frontend, use_old_api=use_old_api) |
Oops, something went wrong.