|
1 | 1 | # Copyright (C) 2018-2024 Intel Corporation
|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
| 4 | +import numpy as np |
4 | 5 | import pytest
|
5 | 6 | import tensorflow as tf
|
6 | 7 | from common.tf_layer_test_class import CommonTFLayerTest
|
7 | 8 |
|
| 9 | +rng = np.random.default_rng(233453) |
| 10 | + |
8 | 11 |
|
9 | 12 | 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 |
11 | 22 | tf.compat.v1.reset_default_graph()
|
12 | 23 | # Create the graph and model
|
13 | 24 | 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') |
15 | 26 | tf.raw_ops.L2Loss(t=input, name='l2_loss')
|
16 | 27 | tf.compat.v1.global_variables_initializer()
|
17 |
| - |
18 | 28 | tf_net = sess.graph_def
|
19 | 29 |
|
20 | 30 | return tf_net, None
|
21 | 31 |
|
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]) |
28 | 34 | @pytest.mark.precommit
|
29 | 35 | @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, |
31 | 38 | 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), |
37 | 45 | 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