diff --git a/src/frontends/tensorflow/src/op/depth_to_space.cpp b/src/frontends/tensorflow/src/op/depth_to_space.cpp index e93ac4f8403..5b5f8f05a20 100644 --- a/src/frontends/tensorflow/src/op/depth_to_space.cpp +++ b/src/frontends/tensorflow/src/op/depth_to_space.cpp @@ -20,7 +20,7 @@ OutputVector translate_depth_to_space_op(const NodeContext& node) { // retrieve attributes auto block_size = node.get_attribute("block_size"); - auto data_format = node.get_attribute("data_format"); + auto data_format = node.get_attribute("data_format", "NHWC"); TENSORFLOW_OP_VALIDATION(node, data_format == "NHWC" || data_format == "NCHW", diff --git a/src/frontends/tensorflow/src/op/space_to_depth.cpp b/src/frontends/tensorflow/src/op/space_to_depth.cpp index b98d0b15078..5fe661f9037 100644 --- a/src/frontends/tensorflow/src/op/space_to_depth.cpp +++ b/src/frontends/tensorflow/src/op/space_to_depth.cpp @@ -14,20 +14,24 @@ namespace tensorflow { namespace op { OutputVector translate_space_to_depth_op(const NodeContext& node) { - auto input = node.get_input(0); + default_op_checks(node, 1, {"SpaceToDepth"}); + auto input_data = node.get_input(0); + // retrieve attributes auto block_size = node.get_attribute("block_size"); - auto data_format = node.get_attribute("data_format"); - - TENSORFLOW_OP_VALIDATION(node, data_format == "NHWC" || data_format == "NCHW", "Unsupported data format."); + auto data_format = node.get_attribute("data_format", "NHWC"); + TENSORFLOW_OP_VALIDATION(node, + data_format == "NHWC" || data_format == "NCHW", + "TensorFlow Frontend supports input data for SpaceToDepth either in NHWC or NCHW format."); bool is_nhwc = (data_format == "NHWC"); - convert_nhwc_to_nchw(is_nhwc, input); - auto ng_mode = SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST; - auto res = make_shared(input, ng_mode, block_size)->output(0); - convert_nchw_to_nhwc(is_nhwc, res); - set_node_name(node.get_name(), res.get_node_shared_ptr()); - return {res}; + + convert_nhwc_to_nchw(is_nhwc, input_data); + auto mode = SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST; + auto space_to_depth = make_shared(input_data, mode, block_size)->output(0); + convert_nchw_to_nhwc(is_nhwc, space_to_depth); + set_node_name(node.get_name(), space_to_depth.get_node_shared_ptr()); + return {space_to_depth}; } } // namespace op } // namespace tensorflow diff --git a/tests/layer_tests/tensorflow_tests/test_tf_SpaceToDepth.py b/tests/layer_tests/tensorflow_tests/test_tf_SpaceToDepth.py new file mode 100644 index 00000000000..b884327b0b7 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_SpaceToDepth.py @@ -0,0 +1,35 @@ +# Copyright (C) 2018-2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestSpaceToDepth(CommonTFLayerTest): + def create_space_to_depth_net(self, input_shape, block_size, data_format): + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(tf.float32, input_shape, 'x') + tf.raw_ops.SpaceToDepth(input=x, block_size=block_size, data_format=data_format) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(input_shape=[2, 12, 16, 3], block_size=2, data_format='NHWC'), + dict(input_shape=[3, 6, 15, 2], block_size=3, data_format='NHWC'), + # On CPU TensorFlow does not support 'NCHW' for SpaceToDepth + # dict(input_shape=[2, 3, 10, 10], block_size=5, data_format='NCHW'), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_space_to_depth_basic(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_space_to_depth_net(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api)