Skip to content

Commit

Permalink
[Layer Test] Remove legacy code from layer tests (openvinotoolkit#23067)
Browse files Browse the repository at this point in the history
**Details:** This legacy code previously was used for validation legacy
FE in legacy inference API

**Ticket:** TBD

Signed-off-by: Kazantsev, Roman <[email protected]>
  • Loading branch information
rkazants authored Feb 26, 2024
1 parent 69736c6 commit fd451f5
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 318 deletions.
24 changes: 3 additions & 21 deletions tests/layer_tests/common/utils/tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import numpy as np
import tensorflow as tf

from openvino.tools.mo.ops.op import PermuteAttrs


os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'


Expand Down Expand Up @@ -98,7 +95,8 @@ def summarize_graph(model_path, output_nodes_for_freeze=None, reshape_net=None):
variables = list()
outputs = list()
graph = load_graph(model_path, output_nodes_for_freeze)
unlikely_output_types = ['Const', 'Assign', 'NoOp', 'Placeholder', 'Assert', 'switch_t', 'switch_f', 'TensorArrayCloseV3']
unlikely_output_types = ['Const', 'Assign', 'NoOp', 'Placeholder', 'Assert', 'switch_t', 'switch_f',
'TensorArrayCloseV3']
control_dependents_map = collect_control_dependencies(graph)
for node in graph.as_graph_def().node:
if node.op == 'Placeholder':
Expand Down Expand Up @@ -130,27 +128,11 @@ def summarize_graph(model_path, output_nodes_for_freeze=None, reshape_net=None):
return result


def permute_nhwc_to_nchw(shape, use_legacy_frontend=True):
if not use_legacy_frontend:
return shape
perm = PermuteAttrs.get_nhwc_to_nchw_permutation(len(shape)).perm
new_shape = np.array(shape)[perm]
return new_shape


def permute_nchw_to_nhwc(shape, use_legacy_frontend=True):
if not use_legacy_frontend:
return shape
perm = PermuteAttrs.get_nchw_to_nhwc_permutation(len(shape)).perm
new_shape = np.array(shape)[perm]
return new_shape


def permute_axis(axis, permutation_inv):
return permutation_inv[axis]


def save_to_pb(tf_model, path_to_saved_tf_model, model_name = 'model.pb'):
def save_to_pb(tf_model, path_to_saved_tf_model, model_name='model.pb'):
tf.io.write_graph(tf_model, path_to_saved_tf_model, model_name, False)
assert os.path.isfile(os.path.join(path_to_saved_tf_model, model_name)), "model.pb haven't been saved " \
"here: {}".format(path_to_saved_tf_model)
Expand Down
36 changes: 3 additions & 33 deletions tests/layer_tests/tensorflow_tests/test_tf_BiasAdd.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import pytest

from common.tf_layer_test_class import CommonTFLayerTest
from common.utils.tf_utils import permute_nchw_to_nhwc
import tensorflow as tf
import numpy as np
from common.tf_layer_test_class import CommonTFLayerTest


class TestBiasAdd(CommonTFLayerTest):
def create_bias_add_placeholder_const_net(self, shape, ir_version, use_legacy_frontend, output_type=tf.float32):
"""
Tensorflow net IR net
Placeholder->BiasAdd => Placeholder->Add
/ /
Const-------/ Const-------/
"""

tf.compat.v1.reset_default_graph()

# Create the graph and model
with tf.compat.v1.Session() as sess:
tf_x_shape = shape.copy()

tf_x_shape = permute_nchw_to_nhwc(tf_x_shape, use_legacy_frontend)
tf_y_shape = tf_x_shape[-1:]

x = tf.compat.v1.placeholder(output_type, tf_x_shape, 'Input')
Expand All @@ -45,30 +33,12 @@ def create_bias_add_placeholder_const_net(self, shape, ir_version, use_legacy_fr
return tf_net, ref_net

def create_bias_add_2_consts_net(self, shape, ir_version, use_legacy_frontend, output_type=tf.float32):
"""
Tensorflow net IR net
Const->BiasAdd-->Concat => Const---->Concat
/ / /
Const--/ / Placeholder-/
/
Placeholder---/
"""

#
# Create Tensorflow model
#

tf.compat.v1.reset_default_graph()

tf_concat_axis = -1

# Create the graph and model
with tf.compat.v1.Session() as sess:
tf_x_shape = shape.copy()

tf_x_shape = permute_nchw_to_nhwc(tf_x_shape, use_legacy_frontend)
tf_y_shape = tf_x_shape[-1:]

constant_value_x = np.random.randint(-256, 256, tf_x_shape).astype(output_type.as_numpy_dtype())
Expand Down
24 changes: 4 additions & 20 deletions tests/layer_tests/tensorflow_tests/test_tf_BinaryOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import numpy as np
import pytest

from common.tf_layer_test_class import CommonTFLayerTest
from common.utils.tf_utils import permute_nchw_to_nhwc


def generate_input(op_type, size):
Expand Down Expand Up @@ -44,14 +42,6 @@ def _prepare_input(self, inputs_dict):

def create_add_placeholder_const_net(self, x_shape, y_shape, ir_version, op_type,
use_legacy_frontend):
"""
Tensorflow net IR net
Placeholder->BinaryOp => Placeholder->BinaryOp
/ /
Const-------/ Const-------/
"""
if not use_legacy_frontend and op_type == "Xdivy":
pytest.xfail(reason="95499")

Expand Down Expand Up @@ -98,14 +88,8 @@ def create_add_placeholder_const_net(self, x_shape, y_shape, ir_version, op_type
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
tf_x_shape = x_shape.copy()
tf_y_shape = y_shape.copy()

tf_x_shape = permute_nchw_to_nhwc(tf_x_shape, use_legacy_frontend)
tf_y_shape = permute_nchw_to_nhwc(tf_y_shape, use_legacy_frontend)

x = tf.compat.v1.placeholder(type, tf_x_shape, 'Input')
constant_value = generate_input(op_type, tf_y_shape)
x = tf.compat.v1.placeholder(type, x_shape, 'Input')
constant_value = generate_input(op_type, y_shape)
if (constant_value == 0).all():
# Avoid elimination of the layer from IR
constant_value = constant_value + 1
Expand All @@ -114,7 +98,7 @@ def create_add_placeholder_const_net(self, x_shape, y_shape, ir_version, op_type
if not op_type in op_type_kw_args:
op = op_type_to_tf[op_type](x, y, name="Operation")
else:
op = op_type_to_tf[op_type](x = x, y = y, name="Operation")
op = op_type_to_tf[op_type](x=x, y=y, name="Operation")

tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
Expand All @@ -134,7 +118,7 @@ def create_add_placeholder_const_net(self, x_shape, y_shape, ir_version, op_type
'Equal', 'NotEqual', 'Mod', 'Greater', 'GreaterEqual', 'Less',
'LessEqual',
'LogicalAnd', 'LogicalOr', 'LogicalXor', 'FloorMod', 'FloorDiv',
'Xdivy', 'BitwiseAnd', 'BitwiseOr', 'BitwiseXor',])
'Xdivy', 'BitwiseAnd', 'BitwiseOr', 'BitwiseXor', ])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
Expand Down
23 changes: 2 additions & 21 deletions tests/layer_tests/tensorflow_tests/test_tf_Eltwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@
import pytest

from common.tf_layer_test_class import CommonTFLayerTest
from common.utils.tf_utils import permute_nchw_to_nhwc


class TestEltwise(CommonTFLayerTest):
def create_eltwise_net(self, shape, operation, ir_version, use_legacy_frontend):
"""
Tensorflow net IR net
Inputs->Eltwise => Inputs->Eltwise
"""

import tensorflow as tf

tf.compat.v1.reset_default_graph()

# Create the graph and model
with tf.compat.v1.Session() as sess:

tf_x_shape = shape.copy()

tf_x_shape = permute_nchw_to_nhwc(tf_x_shape, use_legacy_frontend)

x = tf.compat.v1.placeholder(tf.float32, tf_x_shape, 'Input')
y = tf.compat.v1.placeholder(tf.float32, tf_x_shape, 'Input') # Input_1 in graph_def
x = tf.compat.v1.placeholder(tf.float32, shape, 'Input')
y = tf.compat.v1.placeholder(tf.float32, shape, 'Input') # Input_1 in graph_def

if operation == 'sum':
tf.add(x, y, name='Operation')
Expand All @@ -40,12 +27,6 @@ def create_eltwise_net(self, shape, operation, ir_version, use_legacy_frontend):
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def

#
# Create reference IR net
# Please, specify 'type': 'Input' for input node
# Moreover, do not forget to validate ALL layer attributes!!!
#

ref_net = None

return tf_net, ref_net
Expand Down
70 changes: 38 additions & 32 deletions tests/layer_tests/tensorflow_tests/test_tf_Equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import pytest
import tensorflow as tf
from common.tf_layer_test_class import CommonTFLayerTest
from common.utils.tf_utils import permute_nchw_to_nhwc

import logging

# Testing operation Equal
# Documentation: https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/equal
Expand Down Expand Up @@ -44,7 +42,8 @@ def _prepare_input(self, inputs_dict):
# y_shape - second argument, should be an array (shape). Might be None if y_value is passed
# x_value - fills x_shape by chosen value, uses randint instead
# y_value - if y_shape is None - uses y_value as scalar, otherwise fills y_shape by chosen value, uses randint instead
def create_tf_equal_net(self, ir_version, use_legacy_frontend, x_shape, output_type, y_shape = None, x_value = None, y_value = None):
def create_tf_equal_net(self, ir_version, use_legacy_frontend, x_shape, output_type, y_shape=None, x_value=None,
y_value=None):
self.x_value = x_value
self.y_value = y_value
self.output_type = output_type
Expand All @@ -56,11 +55,6 @@ def create_tf_equal_net(self, ir_version, use_legacy_frontend, x_shape, output_t
self.x_shape = x_shape.copy() if isinstance(x_shape, list) else x_shape
self.y_shape = y_shape.copy() if isinstance(y_shape, list) else y_shape

if isinstance(x_shape, list):
self.x_shape = permute_nchw_to_nhwc(self.x_shape, use_legacy_frontend)
if isinstance(y_shape, list):
self.y_shape = permute_nchw_to_nhwc(self.y_shape, use_legacy_frontend)

if self.output_type == np.float16:
x = tf.compat.v1.placeholder(tf.float16, self.x_shape, 'Input')
elif self.output_type == np.float32:
Expand Down Expand Up @@ -98,15 +92,18 @@ def create_tf_equal_net(self, ir_version, use_legacy_frontend, x_shape, output_t

test_data_int32 = [
pytest.param(
dict(x_shape=[2,3], y_shape=[2,3]), #Comparing shapes with random values (verifies false and possible true)
dict(x_shape=[2, 3], y_shape=[2, 3]),
# Comparing shapes with random values (verifies false and possible true)
marks=pytest.mark.precommit_tf_fe),
dict(x_shape=[2,3], y_value=2), #Comparing shape with scalar value (verifies false and possible true)
dict(x_shape=[2,3], y_shape=[2,3], #Comparing shapes with same values (verifies true statement)
dict(x_shape=[2, 3], y_value=2), # Comparing shape with scalar value (verifies false and possible true)
dict(x_shape=[2, 3], y_shape=[2, 3], # Comparing shapes with same values (verifies true statement)
x_value=2, y_value=2),
dict(x_shape=[2,3], y_value=2, #Comparing shape with scalar value (verifies true statement)
dict(x_shape=[2, 3], y_value=2, # Comparing shape with scalar value (verifies true statement)
x_value=2),
dict(x_shape=[2,3,2], y_shape=[2]), #Comparing shapes with different dimensions, random values (false and possible true)
dict(x_shape=[1,2,3,4], y_shape=[1,2,3,4]) #Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
dict(x_shape=[2, 3, 2], y_shape=[2]),
# Comparing shapes with different dimensions, random values (false and possible true)
dict(x_shape=[1, 2, 3, 4], y_shape=[1, 2, 3, 4])
# Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
]

@pytest.mark.parametrize("params", test_data_int32)
Expand All @@ -120,15 +117,18 @@ def test_tf_equal_int32(self, params, ie_device, precision, ir_version, temp_dir

test_data_int64 = [
pytest.param(
dict(x_shape=[2,3], y_shape=[2,3]), #Comparing shapes with random values (verifies false and possible true)
dict(x_shape=[2, 3], y_shape=[2, 3]),
# Comparing shapes with random values (verifies false and possible true)
marks=pytest.mark.precommit_tf_fe),
dict(x_shape=[2,3], y_value=2), #Comparing shape with scalar value (verifies false and possible true)
dict(x_shape=[2,3], y_shape=[2,3], #Comparing shapes with same values (verifies true statement)
dict(x_shape=[2, 3], y_value=2), # Comparing shape with scalar value (verifies false and possible true)
dict(x_shape=[2, 3], y_shape=[2, 3], # Comparing shapes with same values (verifies true statement)
x_value=2, y_value=2),
dict(x_shape=[2,3], y_value=2, #Comparing shape with scalar value (verifies true statement)
dict(x_shape=[2, 3], y_value=2, # Comparing shape with scalar value (verifies true statement)
x_value=2),
dict(x_shape=[2,3,2], y_shape=[2]), #Comparing shapes with different dimensions, random values (false and possible true)
dict(x_shape=[1,2,3,4], y_shape=[1,2,3,4]) #Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
dict(x_shape=[2, 3, 2], y_shape=[2]),
# Comparing shapes with different dimensions, random values (false and possible true)
dict(x_shape=[1, 2, 3, 4], y_shape=[1, 2, 3, 4])
# Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
]

@pytest.mark.parametrize("params", test_data_int64)
Expand All @@ -142,18 +142,20 @@ def test_tf_equal_int64(self, params, ie_device, precision, ir_version, temp_dir

# Values for checking important corner cases for float values
# expect: false false false false false false true false true
x_corner = [1. , 1. , 1. , np.nan, np.nan, np.nan , np.inf, np.inf , np.NINF]
x_corner = [1., 1., 1., np.nan, np.nan, np.nan, np.inf, np.inf, np.NINF]
y_corner = [np.nan, np.inf, np.NINF, np.nan, np.inf, np.NINF, np.inf, np.NINF, np.NINF]

test_data_float16 = [
pytest.param(
dict(x_shape=[2,3], y_shape=[2,3]), #Comparing shapes with different dimensions, random values (false and possible true)
dict(x_shape=[2, 3], y_shape=[2, 3]),
# Comparing shapes with different dimensions, random values (false and possible true)
marks=pytest.mark.precommit_tf_fe),
pytest.param(
dict(x_shape=[9], y_shape=[9], #Comparing shapes which contains corner cases
x_value = x_corner, y_value = y_corner),
dict(x_shape=[9], y_shape=[9], # Comparing shapes which contains corner cases
x_value=x_corner, y_value=y_corner),
marks=pytest.mark.xfail(reason="94234")),
dict(x_shape=[1,2,3,4], y_shape=[1,2,3,4]) #Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
dict(x_shape=[1, 2, 3, 4], y_shape=[1, 2, 3, 4])
# Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
]

@pytest.mark.parametrize("params", test_data_float16)
Expand All @@ -167,13 +169,15 @@ def test_tf_equal_float16(self, params, ie_device, precision, ir_version, temp_d

test_data_float32 = [
pytest.param(
dict(x_shape=[2,3], y_shape=[2,3]), #Comparing shapes with random values (verifies false and possible true)
dict(x_shape=[2, 3], y_shape=[2, 3]),
# Comparing shapes with random values (verifies false and possible true)
marks=pytest.mark.precommit_tf_fe),
pytest.param(
dict(x_shape=[9], y_shape=[9], #Comparing shapes which contains corner cases
dict(x_shape=[9], y_shape=[9], # Comparing shapes which contains corner cases
x_value=x_corner, y_value=y_corner),
marks=pytest.mark.xfail(reason="94234")),
dict(x_shape=[1,2,3,4], y_shape=[1,2,3,4]) #Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
dict(x_shape=[1, 2, 3, 4], y_shape=[1, 2, 3, 4])
# Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
]

@pytest.mark.parametrize("params", test_data_float32)
Expand All @@ -187,13 +191,15 @@ def test_tf_equal_float32(self, params, ie_device, precision, ir_version, temp_d

test_data_float64 = [
pytest.param(
dict(x_shape=[2,3], y_shape=[2,3]), #Comparing shapes with different dimensions, random values (false and possible true)
dict(x_shape=[2, 3], y_shape=[2, 3]),
# Comparing shapes with different dimensions, random values (false and possible true)
marks=pytest.mark.precommit_tf_fe),
pytest.param(
dict(x_shape=[9], y_shape=[9], #Comparing shapes which contains corner cases
x_value = x_corner, y_value = y_corner),
dict(x_shape=[9], y_shape=[9], # Comparing shapes which contains corner cases
x_value=x_corner, y_value=y_corner),
marks=pytest.mark.xfail(reason="94234")),
dict(x_shape=[1,2,3,4], y_shape=[1,2,3,4]) #Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
dict(x_shape=[1, 2, 3, 4], y_shape=[1, 2, 3, 4])
# Comparing shapes with different dimensions (more than 3, for case with nchw/nhcw), random values (false and possible true)
]

@pytest.mark.parametrize("params", test_data_float64)
Expand Down
Loading

0 comments on commit fd451f5

Please sign in to comment.