Skip to content

[Layer Tests] Remove legacy frontend from layer tests #30214

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
60 changes: 21 additions & 39 deletions tests/layer_tests/common/layer_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,38 @@ def get_framework_results(self, inputs_dict, model_path):
" the specific framework")

def _test(self, framework_model, ref_net, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend=False, infer_timeout=60, enabled_transforms='',
infer_timeout=60, enabled_transforms='',
disabled_transforms='', **kwargs):
"""
:param enabled_transforms/disabled_transforms: string with idxs of transforms that should be enabled/disabled.
Example: "transform_1,transform_2"
"""
model_path = self.produce_model_path(framework_model=framework_model, save_path=temp_dir)
self.use_legacy_frontend = use_legacy_frontend
# TODO Pass environment variables via subprocess environment
os.environ['MO_ENABLED_TRANSFORMS'] = enabled_transforms
os.environ['MO_DISABLED_TRANSFORMS'] = disabled_transforms

compress_to_fp16 = False if precision == 'FP32' else True

if use_legacy_frontend:
mo_params = {self.input_model_key: model_path,
"output_dir": temp_dir,
"compress_to_fp16": compress_to_fp16,
"model_name": 'model'}

if 'input_shapes' in kwargs and len(kwargs['input_shapes']):
input_shapes_str = []
for ishape in kwargs['input_shapes']:
input_shapes_str.append('[' + ','.join([str(i) for i in ishape]) + ']')
mo_params.update(dict(input_shape=','.join(input_shapes_str)))

if 'input_names' in kwargs and len(kwargs['input_names']):
mo_params.update(dict(input=','.join(kwargs['input_names'])))
mo_params["use_legacy_frontend"] = True
else:
# pack input parameters for convert_model of OVC
# that are different from MO
mo_params = {"input_model": model_path,
"output_dir": temp_dir,
"compress_to_fp16": compress_to_fp16
}

if 'input_shapes' in kwargs and 'input_names' in kwargs:
input_shapes = kwargs['input_shapes']
input_names = kwargs['input_names']
assert len(input_shapes) == len(input_names)
input_dict = {}
for input_name, input_shape in zip(input_names, input_shapes):
input_dict[input_name] = input_shape
mo_params.update(dict(input=input_dict))
elif 'input_names' in kwargs:
mo_params.update(dict(input=kwargs['input_names']))
elif 'input_shapes' in kwargs:
mo_params.update(dict(input=kwargs['input_shapes']))
# pack input parameters for convert_model of OVC
# that are different from MO
mo_params = {"input_model": model_path,
"output_dir": temp_dir,
"compress_to_fp16": compress_to_fp16
}

if 'input_shapes' in kwargs and 'input_names' in kwargs:
input_shapes = kwargs['input_shapes']
input_names = kwargs['input_names']
assert len(input_shapes) == len(input_names)
input_dict = {}
for input_name, input_shape in zip(input_names, input_shapes):
input_dict[input_name] = input_shape
mo_params.update(dict(input=input_dict))
elif 'input_names' in kwargs:
mo_params.update(dict(input=kwargs['input_names']))
elif 'input_shapes' in kwargs:
mo_params.update(dict(input=kwargs['input_shapes']))

exit_code, stderr = generate_ir_python_api(**mo_params)

Expand All @@ -99,8 +82,7 @@ def _test(self, framework_model, ref_net, ie_device, precision, ir_version, temp

ie_engine = InferAPI(model=path_to_xml,
weights=path_to_bin,
device=ie_device,
use_legacy_frontend=use_legacy_frontend)
device=ie_device)
# Prepare feed dict
if 'kwargs_to_prepare_input' in kwargs and kwargs['kwargs_to_prepare_input']:
inputs_dict = self._prepare_input(ie_engine.get_inputs_info(precision),
Expand Down
13 changes: 3 additions & 10 deletions tests/layer_tests/common/layer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ def infer(self, input_data, config=None, infer_timeout=10):


class InferAPI(BaseInfer):
def __init__(self, model, weights, device, use_legacy_frontend):
def __init__(self, model, weights, device):
super().__init__('OpenVINO')
self.device = device
self.model = model
self.weights = weights
self.use_legacy_frontend = use_legacy_frontend

def fw_infer(self, input_data, config=None):
print("OpenVINO version: {}".format(ie2_get_version()))
Expand All @@ -69,14 +68,8 @@ def fw_infer(self, input_data, config=None):
# For the new frontend we make this the right way because
# we know that tensor can have several names due to fusing
# and one of them the framework uses
if not self.use_legacy_frontend:
for tensor_name in out_obj.get_names():
result[tensor_name] = out_tensor
else:
for tensor_name in out_obj.get_names():
result[tensor_name] = out_tensor
tensor_name = tensor_name.split(':')[0]
result[tensor_name] = out_tensor
for tensor_name in out_obj.get_names():
result[tensor_name] = out_tensor

if "exec_net" in locals():
del exec_net
Expand Down
37 changes: 4 additions & 33 deletions tests/layer_tests/common/tf2_layer_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,14 @@ def get_framework_results(self, inputs_dict, model_path):
return self.get_tf2_keras_results(inputs_dict, model_path)
else:
# get results from tflite
return get_tflite_results(self.use_legacy_frontend, inputs_dict, model_path)
return get_tflite_results(inputs_dict, model_path)

def get_tf2_keras_results(self, inputs_dict, model_path):
import tensorflow as tf

result = dict()
if not self.use_legacy_frontend:
imported = tf.saved_model.load(model_path)
f = imported.signatures["serving_default"]
result = f(**inputs_dict)
else:
# load a model
loaded_model = tf.keras.models.load_model(model_path, custom_objects=None)
# prepare input
input_for_model = []
# order inputs based on input names in tests
# since TF2 Keras model accepts a list of tensors for prediction
for input_name in sorted(inputs_dict):
input_value = inputs_dict[input_name]
input_for_model.append(input_value)
if len(input_for_model) == 1:
input_for_model = input_for_model[0]

# infer by original framework and complete a dictionary with reference results
tf_res_list = loaded_model(input_for_model)
if tf.is_tensor(tf_res_list):
tf_res_list = [tf_res_list]
else:
# in this case tf_res_list is a list of the single tuple of outputs
tf_res_list = tf_res_list[0]

for ind, tf_res in enumerate(tf_res_list):
if ind == 0:
output = "Identity"
else:
output = "Identity_{}".format(ind)
tf_res = tf_res.numpy()
result[output] = tf_res
imported = tf.saved_model.load(model_path)
f = imported.signatures["serving_default"]
result = f(**inputs_dict)

return result
65 changes: 23 additions & 42 deletions tests/layer_tests/common/tf_layer_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def get_tf_results(self, inputs_dict, model_path):
graph_summary = summarize_graph(model_path=model_path)
outputs_list = graph_summary["outputs"]
fw_outputs_list = [out + ":0" for out in outputs_list]
if not self.use_legacy_frontend:
outputs_list = fw_outputs_list
outputs_list = fw_outputs_list

tf.compat.v1.reset_default_graph()

Expand All @@ -65,50 +64,33 @@ def get_framework_results(self, inputs_dict, model_path):
return self.get_tf_results(inputs_dict, model_path)
else:
# get results from tflite
return get_tflite_results(self.use_legacy_frontend, inputs_dict, model_path)
return get_tflite_results(inputs_dict, model_path)

def _test(self, framework_model, ref_net, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend=False, infer_timeout=60, **kwargs):
infer_timeout=60, **kwargs):
model_path = self.produce_model_path(framework_model=framework_model, save_path=temp_dir)
self.use_legacy_frontend = use_legacy_frontend

compress_to_fp16 = False if precision == 'FP32' else True

if use_legacy_frontend:
mo_params = {self.input_model_key: model_path,
"output_dir": temp_dir,
"compress_to_fp16": compress_to_fp16,
"model_name": 'model'}

if 'input_shapes' in kwargs and len(kwargs['input_shapes']):
input_shapes_str = []
for ishape in kwargs['input_shapes']:
input_shapes_str.append('[' + ','.join([str(i) for i in ishape]) + ']')
mo_params.update(dict(input_shape=','.join(input_shapes_str)))

if 'input_names' in kwargs and len(kwargs['input_names']):
mo_params.update(dict(input=','.join(kwargs['input_names'])))
mo_params["use_legacy_frontend"] = True
else:
# pack input parameters for convert_model of OVC
# that are different from MO
mo_params = {"input_model": model_path,
"output_dir": temp_dir,
"compress_to_fp16": compress_to_fp16
}

if 'input_shapes' in kwargs and 'input_names' in kwargs:
input_shapes = kwargs['input_shapes']
input_names = kwargs['input_names']
assert len(input_shapes) == len(input_names)
input_dict = {}
for input_name, input_shape in zip(input_names, input_shapes):
input_dict[input_name] = input_shape
mo_params.update(dict(input=input_dict))
elif 'input_names' in kwargs:
mo_params.update(dict(input=kwargs['input_names']))
elif 'input_shapes' in kwargs:
mo_params.update(dict(input=kwargs['input_shapes']))
# pack input parameters for convert_model of OVC
# that are different from MO
mo_params = {"input_model": model_path,
"output_dir": temp_dir,
"compress_to_fp16": compress_to_fp16
}

if 'input_shapes' in kwargs and 'input_names' in kwargs:
input_shapes = kwargs['input_shapes']
input_names = kwargs['input_names']
assert len(input_shapes) == len(input_names)
input_dict = {}
for input_name, input_shape in zip(input_names, input_shapes):
input_dict[input_name] = input_shape
mo_params.update(dict(input=input_dict))
elif 'input_names' in kwargs:
mo_params.update(dict(input=kwargs['input_names']))
elif 'input_shapes' in kwargs:
mo_params.update(dict(input=kwargs['input_shapes']))

exit_code, stderr = generate_ir_python_api(**mo_params)
assert not exit_code, (
Expand All @@ -125,8 +107,7 @@ def _test(self, framework_model, ref_net, ie_device, precision, ir_version, temp

ie_engine = InferAPI(model=path_to_xml,
weights=path_to_bin,
device=ie_device,
use_legacy_frontend=use_legacy_frontend)
device=ie_device)
# Prepare feed dict
if 'kwargs_to_prepare_input' in kwargs and kwargs['kwargs_to_prepare_input']:
inputs_dict = self._prepare_input(ie_engine.get_inputs_info(precision),
Expand Down
2 changes: 1 addition & 1 deletion tests/layer_tests/common/tflite_layer_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def produce_model_path(self, framework_model, save_path):
return self.model_path

def get_framework_results(self, inputs_dict, model_path):
return get_tflite_results(self.use_legacy_frontend, inputs_dict, model_path)
return get_tflite_results(inputs_dict, model_path)

def check_tflite_model_has_only_allowed_ops(self):
if self.allowed_ops is None:
Expand Down
5 changes: 4 additions & 1 deletion tests/layer_tests/common/utils/tflite_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import itertools
import os
import warnings
Expand Down Expand Up @@ -80,7 +83,7 @@ def save_pb_to_tflite(pb_model):
return tflite_model_path


def get_tflite_results(use_legacy_frontend, inputs_dict, model_path):
def get_tflite_results(inputs_dict, model_path):
interpreter = tf.compat.v1.lite.Interpreter(model_path=model_path)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
Expand Down
11 changes: 0 additions & 11 deletions tests/layer_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ def pytest_addoption(parser):
default=11,
action="store",
help="Version of IR to generate by Model Optimizer")
parser.addoption(
"--use_legacy_frontend",
required=False,
action="store_true",
help="Use Model Optimizer with legacy FrontEnd")
parser.addoption(
"--tflite",
required=False,
Expand All @@ -78,12 +73,6 @@ def ir_version(request):
return request.config.getoption('ir_version')


@pytest.fixture(scope="session")
def use_legacy_frontend(request):
"""Fixture function for command-line option."""
return request.config.getoption('use_legacy_frontend')


@pytest.fixture(scope="session")
def tflite(request):
"""Fixture function for command-line option."""
Expand Down
3 changes: 1 addition & 2 deletions tests/layer_tests/onnx_tests/test_roi_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,4 @@ def test_roi_alignv10(self, params, ie_device, precision, ir_version, temp_dir):
if ie_device != "GPU":
self._test(*self.create_net(**params, ir_version=ir_version, onnx_version=10), ie_device, precision,
ir_version,
temp_dir=temp_dir,
use_legacy_frontend=True)
temp_dir=temp_dir)
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create_tf_model_single_input_output(tmp_dir):
@pytest.mark.nightly
@pytest.mark.precommit
def test_mo_convert_tf_model_single_input_output(self, params, ie_device, precision, ir_version,
temp_dir, use_legacy_frontend):
temp_dir):
tf_net_path = self.create_tf_model_single_input_output(temp_dir)

test_params = params['params_test']
Expand Down Expand Up @@ -198,7 +198,7 @@ def create_onnx_model_with_several_outputs(temp_dir):
@pytest.mark.nightly
@pytest.mark.precommit
def test_ovc_convert_model_with_comma_in_names(self, ie_device, precision, ir_version,
temp_dir, use_legacy_frontend):
temp_dir):
onnx_net_path = self.create_onnx_model_with_comma_in_names(temp_dir)
ref_model = self.create_ref_graph_with_comma_in_names()
test_params = {'input_model': onnx_net_path, 'output': 'relu_1,relu_2'}
Expand All @@ -208,7 +208,7 @@ def test_ovc_convert_model_with_comma_in_names(self, ie_device, precision, ir_ve
@pytest.mark.nightly
@pytest.mark.precommit
def test_ovc_convert_model_with_several_output(self, ie_device, precision, ir_version,
temp_dir, use_legacy_frontend):
temp_dir):
onnx_net_path = self.create_onnx_model_with_several_outputs(temp_dir)
convert_model_params = {'input_model': onnx_net_path, 'output': ['Relu_1_data', 'concat']}
cli_tool_params = {'input_model': onnx_net_path, 'output': 'Relu_1_data,concat'}
Expand All @@ -218,7 +218,7 @@ def test_ovc_convert_model_with_several_output(self, ie_device, precision, ir_ve

@pytest.mark.nightly
@pytest.mark.precommit
def test_non_numpy_types(self, ie_device, precision, ir_version, temp_dir, use_legacy_frontend):
def test_non_numpy_types(self, ie_device, precision, ir_version, temp_dir):
import tensorflow as tf
def func(a, b):
return [a, b]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def create_ref_graph2():
@pytest.mark.nightly
@pytest.mark.precommit
def test_mo_convert_extensions(self, params, ie_device, precision, ir_version,
temp_dir, use_legacy_frontend):
temp_dir):
onnx_net_path = self.create_onnx_model(temp_dir)

test_params = params['params_test']
Expand Down
2 changes: 1 addition & 1 deletion tests/layer_tests/ovc_python_api_tests/test_paddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class TestPaddleConversionParams(CommonMOConvertTest):
@pytest.mark.parametrize("params", test_data)
@pytest.mark.nightly
def test_conversion_params(self, params, ie_device, precision, ir_version,
temp_dir, use_legacy_frontend):
temp_dir):
fw_model = params['fw_model']
test_params = params['params_test']
ref_model = params['ref_model']
Expand Down
Loading
Loading