From 033a5151e20979eb464786c14cabe329c4baf037 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Mon, 12 Aug 2024 14:24:03 +0400 Subject: [PATCH] [TF FE] Stabilize Conv2DBackpropInput tests on all platforms (#26011) **Details:** Stabilize Conv2DBackpropInput tests on all platforms **Ticket:** 105818 --------- Signed-off-by: Kazantsev, Roman --- .../test_tf_Conv2DBackprop.py | 77 ------------------- .../test_tf_Conv2DBackpropInput.py | 68 ++++++++++++++++ 2 files changed, 68 insertions(+), 77 deletions(-) delete mode 100644 tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackprop.py create mode 100644 tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackpropInput.py diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackprop.py b/tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackprop.py deleted file mode 100644 index a87cec0fe11813..00000000000000 --- a/tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackprop.py +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright (C) 2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -import numpy as np -import pytest - -from common.tf_layer_test_class import CommonTFLayerTest - -import logging - -# Testing operation Conv2DBackpropInput -# Documentation: https://www.tensorflow.org/api_docs/python/tf/raw_ops/Conv2DBackpropInput - -class TestConv2DBackprop(CommonTFLayerTest): - # input_shape - should be an array, shape of input tensor in format [batch, height, width, channels] - # input_filter - should be an array, defines a filter - # input_strides - should be an array, defines strides of a sliding window to use - # input_padding - should be a string, defines padding algorithm - # ir_version - common parameter - # use_legacy_frontend - common parameter - def create_conv2dbackprop_placeholder_const_net(self, input_shape, input_filter, out_backprop, input_strides, input_padding, dilations, ir_version, use_legacy_frontend): - """ - TensorFlow net IR net - - Placeholder->Conv2DBackpropInput => Placeholder->Transpose->ConvolutionBackpropData->Transpose - / / - Placeholder-/ Placeholder->Transpose-/ - - """ - - import tensorflow as tf - - if dilations is None: - dilations = [1, 1, 1, 1] #default value regarding Documentation - else: - pytest.skip('Dilations != 1 isn\' supported on CPU by TensorFlow') - - tf.compat.v1.reset_default_graph() - - # Create the graph and model - with tf.compat.v1.Session() as sess: - tf_input = tf.constant(input_shape) - tf_filter = tf.compat.v1.placeholder(tf.float32, input_filter, "Input") - tf_backprop = tf.compat.v1.placeholder(tf.float32, out_backprop, "InputBack") - - tf.raw_ops.Conv2DBackpropInput(input_sizes = tf_input, filter = tf_filter, out_backprop = tf_backprop, strides = input_strides, padding = input_padding, dilations = dilations) - - tf.compat.v1.global_variables_initializer() - tf_net = sess.graph_def - - ref_net = None - - return tf_net, ref_net - - test_data = [ - dict(input_shape=[1, 10, 10, 1], input_filter=[1, 1, 1, 1], out_backprop=[1, 10, 10, 1], input_strides=[1, 1, 1, 1], input_padding='SAME', dilations=None), - dict(input_shape=[1, 10, 10, 3], input_filter=[2, 2, 3, 3], out_backprop=[1, 10, 10, 3], input_strides=[1, 1, 1, 1], input_padding='SAME', dilations=None), - dict(input_shape=[1, 10, 10, 3], input_filter=[2, 2, 3, 3], out_backprop=[1, 5, 5, 3], input_strides=[1, 2, 2, 1], input_padding='SAME', dilations=None), - dict(input_shape=[1, 10, 10, 1], input_filter=[1, 1, 1, 1], out_backprop=[1, 10, 10, 1], input_strides=[1, 1, 1, 1], input_padding='VALID', dilations=None), - dict(input_shape=[1, 10, 10, 3], input_filter=[2, 2, 3, 3], out_backprop=[1, 9, 9, 3], input_strides=[1, 1, 1, 1], input_padding='VALID', dilations=None), - dict(input_shape=[1, 10, 10, 3], input_filter=[2, 2, 3, 3], out_backprop=[1, 5, 5, 3], input_strides=[1, 2, 2, 1], input_padding='VALID', dilations=None), - pytest.param( - dict(input_shape=[1, 56, 56, 3], input_filter=[2, 3, 3, 3], out_backprop=[1, 28, 28, 3], input_strides=[1, 2, 2, 1], input_padding='SAME', dilations=None), - marks=pytest.mark.precommit), - pytest.param( - dict(input_shape=[1, 64, 48, 3], input_filter=[3, 2, 3, 3], out_backprop=[1, 31, 24, 3], input_strides=[1, 2, 2, 1], input_padding='VALID', dilations=None), - marks=pytest.mark.precommit), - ] - - @pytest.mark.parametrize("params", test_data) - @pytest.mark.nightly - def test_conv2dbackprop_placeholder_const(self, params, ie_device, precision, ir_version, temp_dir, - use_legacy_frontend): - self._test(*self.create_conv2dbackprop_placeholder_const_net(**params, ir_version=ir_version, - use_legacy_frontend=use_legacy_frontend), - ie_device, precision, ir_version, temp_dir=temp_dir, - use_legacy_frontend=use_legacy_frontend) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackpropInput.py b/tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackpropInput.py new file mode 100644 index 00000000000000..4383da19f73e2c --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_Conv2DBackpropInput.py @@ -0,0 +1,68 @@ +# Copyright (C) 2023-2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import logging +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + +rng = np.random.default_rng(475912) + + +class TestConv2DBackpropInput(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'filter:0' in inputs_info, "Test error: inputs_info must contain `filter`" + assert 'out_backprop:0' in inputs_info, "Test error: inputs_info must contain `out_backprop`" + + filter_shape = inputs_info['filter:0'] + out_backprop_shape = inputs_info['out_backprop:0'] + inputs_data = {} + if np.issubdtype(self.input_type, np.floating): + inputs_data['filter:0'] = rng.uniform(-1.0, 1.0, filter_shape).astype(self.input_type) + inputs_data['out_backprop:0'] = rng.uniform(-1.0, 1.0, out_backprop_shape).astype(self.input_type) + return inputs_data + + def create_conv2d_backprop_input_net(self, input_sizes, filter_shape, out_backprop_shape, strides, + padding, input_type): + self.input_type = input_type + tf.compat.v1.reset_default_graph() + with tf.compat.v1.Session() as sess: + input_sizes = tf.constant(input_sizes, dtype=tf.int32) + filter = tf.compat.v1.placeholder(input_type, filter_shape, "filter") + out_backprop = tf.compat.v1.placeholder(input_type, out_backprop_shape, "out_backprop") + + tf.raw_ops.Conv2DBackpropInput(input_sizes=input_sizes, filter=filter, out_backprop=out_backprop, + strides=strides, padding=padding) + + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + ref_net = None + + return tf_net, ref_net + + test_data = [ + dict(input_sizes=[1, 10, 10, 1], filter_shape=[1, 1, 1, 1], out_backprop_shape=[1, 10, 10, 1], + strides=[1, 1, 1, 1]), + dict(input_sizes=[1, 10, 10, 3], filter_shape=[2, 2, 3, 3], out_backprop_shape=[1, 5, 5, 3], + strides=[1, 2, 2, 1]), + dict(input_sizes=[1, 20, 20, 3], filter_shape=[2, 2, 3, 3], out_backprop_shape=[1, 10, 10, 3], + strides=[1, 2, 2, 1]), + dict(input_sizes=[1, 20, 20, 1], filter_shape=[1, 1, 1, 1], out_backprop_shape=[1, 20, 20, 1], + strides=[1, 1, 1, 1]), + ] + + @pytest.mark.parametrize("params", test_data) + @pytest.mark.parametrize("padding", ['SAME', 'VALID']) + @pytest.mark.parametrize("input_type", [np.float16, np.float32, np.float64]) + @pytest.mark.precommit + @pytest.mark.nightly + def test_create_conv2d_backprop_input(self, params, padding, input_type, + ie_device, precision, ir_version, temp_dir, use_legacy_frontend): + custom_eps = None + if input_type == np.float16: + custom_eps = 2 * 1e-3 + self._test(*self.create_conv2d_backprop_input_net(**params, padding=padding, input_type=input_type), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_legacy_frontend=use_legacy_frontend, custom_eps=custom_eps)