Skip to content

Commit abbf944

Browse files
authored
[TF FE] Stabilize L2Loss layer tests on all platforms (openvinotoolkit#26151)
**Details:** Stabilize L2Loss layer tests on all platforms **Ticket:** 104863 --------- Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>
1 parent 1335be0 commit abbf944

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
# Copyright (C) 2018-2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4+
import numpy as np
45
import pytest
56
import tensorflow as tf
67
from common.tf_layer_test_class import CommonTFLayerTest
78

9+
rng = np.random.default_rng(233453)
10+
811

912
class TestL2Loss(CommonTFLayerTest):
10-
def create_l2_loss_net(self, input_shape):
13+
def _prepare_input(self, inputs_info):
14+
assert 'input:0' in inputs_info, "Test error: inputs_info must contain `input`"
15+
input_shape = inputs_info['input:0']
16+
inputs_data = {}
17+
inputs_data['input:0'] = rng.uniform(-2.0, 2.0, input_shape).astype(self.input_type)
18+
return inputs_data
19+
20+
def create_l2_loss_net(self, input_shape, input_type):
21+
self.input_type = input_type
1122
tf.compat.v1.reset_default_graph()
1223
# Create the graph and model
1324
with tf.compat.v1.Session() as sess:
14-
input = tf.compat.v1.placeholder(tf.float32, input_shape, 'input')
25+
input = tf.compat.v1.placeholder(input_type, input_shape, 'input')
1526
tf.raw_ops.L2Loss(t=input, name='l2_loss')
1627
tf.compat.v1.global_variables_initializer()
17-
1828
tf_net = sess.graph_def
1929

2030
return tf_net, None
2131

22-
test_data_basic = [
23-
dict(input_shape=[1, 2]),
24-
dict(input_shape=[2, 3, 4]),
25-
]
26-
27-
@pytest.mark.parametrize("params", test_data_basic)
32+
@pytest.mark.parametrize("input_shape", [[], [2], [1, 2], [2, 3, 4]])
33+
@pytest.mark.parametrize("input_type", [np.float16, np.float32, np.float64])
2834
@pytest.mark.precommit
2935
@pytest.mark.nightly
30-
def test_l2_loss_basic(self, params, ie_device, precision, ir_version, temp_dir,
36+
def test_l2_loss_basic(self, input_shape, input_type,
37+
ie_device, precision, ir_version, temp_dir,
3138
use_legacy_frontend):
32-
if ie_device == 'GPU':
33-
pytest.xfail('104863')
34-
if use_legacy_frontend:
35-
pytest.skip("L2Loss is not supported by legacy FE.")
36-
self._test(*self.create_l2_loss_net(**params),
39+
custom_eps = None
40+
if input_type == np.float16:
41+
custom_eps = 3 * 1e-3
42+
if ie_device == 'GPU' and input_shape == []:
43+
pytest.skip("150321: Accessing out-of-range dimension on GPU")
44+
self._test(*self.create_l2_loss_net(input_shape, input_type),
3745
ie_device, precision, ir_version, temp_dir=temp_dir,
38-
use_legacy_frontend=use_legacy_frontend)
46+
use_legacy_frontend=use_legacy_frontend, custom_eps=custom_eps)

0 commit comments

Comments
 (0)