Skip to content

Commit

Permalink
[TF FE] Stabilize L2Loss layer tests on all platforms (openvinotoolki…
Browse files Browse the repository at this point in the history
…t#26151)

**Details:** Stabilize L2Loss layer tests on all platforms

**Ticket:** 104863

---------

Signed-off-by: Kazantsev, Roman <[email protected]>
  • Loading branch information
rkazants authored Aug 21, 2024
1 parent 1335be0 commit abbf944
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tests/layer_tests/tensorflow_tests/test_tf_L2Loss.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
# 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

rng = np.random.default_rng(233453)


class TestL2Loss(CommonTFLayerTest):
def create_l2_loss_net(self, input_shape):
def _prepare_input(self, inputs_info):
assert 'input:0' in inputs_info, "Test error: inputs_info must contain `input`"
input_shape = inputs_info['input:0']
inputs_data = {}
inputs_data['input:0'] = rng.uniform(-2.0, 2.0, input_shape).astype(self.input_type)
return inputs_data

def create_l2_loss_net(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:
input = tf.compat.v1.placeholder(tf.float32, input_shape, 'input')
input = tf.compat.v1.placeholder(input_type, input_shape, 'input')
tf.raw_ops.L2Loss(t=input, name='l2_loss')
tf.compat.v1.global_variables_initializer()

tf_net = sess.graph_def

return tf_net, None

test_data_basic = [
dict(input_shape=[1, 2]),
dict(input_shape=[2, 3, 4]),
]

@pytest.mark.parametrize("params", test_data_basic)
@pytest.mark.parametrize("input_shape", [[], [2], [1, 2], [2, 3, 4]])
@pytest.mark.parametrize("input_type", [np.float16, np.float32, np.float64])
@pytest.mark.precommit
@pytest.mark.nightly
def test_l2_loss_basic(self, params, ie_device, precision, ir_version, temp_dir,
def test_l2_loss_basic(self, input_shape, input_type,
ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
if ie_device == 'GPU':
pytest.xfail('104863')
if use_legacy_frontend:
pytest.skip("L2Loss is not supported by legacy FE.")
self._test(*self.create_l2_loss_net(**params),
custom_eps = None
if input_type == np.float16:
custom_eps = 3 * 1e-3
if ie_device == 'GPU' and input_shape == []:
pytest.skip("150321: Accessing out-of-range dimension on GPU")
self._test(*self.create_l2_loss_net(input_shape, input_type),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)
use_legacy_frontend=use_legacy_frontend, custom_eps=custom_eps)

0 comments on commit abbf944

Please sign in to comment.