From 57df7a44b7f24f98dd4d0066af5133da01206e68 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Tue, 19 Sep 2023 15:03:06 +0200 Subject: [PATCH] Refactor CTCGreedyDecoderSeqLenLayerTest, GreedyDecoderLayerTest, CTCLossLayerTest (#19842) * Refactor CTCGreedyDecoderSeqLenLayerTest * Refactor usingGreedyDecoderLayerTest * Refactor CTCLossLayerTest --- .../single_layer_tests/ctc_greedy_decoder.cpp | 39 +++--- .../ctc_greedy_decoder_seq_len.cpp | 31 +++-- .../single_layer_tests/ctc_loss.cpp | 29 ++-- .../single_op_tests/ctc_greedy_decoder.hpp | 15 +++ .../ctc_greedy_decoder_seq_len.hpp | 15 +++ .../include/single_op_tests/ctc_loss.hpp | 15 +++ .../single_op/ctc_greedy_decoder.hpp | 31 +++++ .../single_op/ctc_greedy_decoder_seq_len.hpp | 36 +++++ .../single_op/ctc_loss.hpp | 43 ++++++ .../src/single_op/ctc_greedy_decoder.cpp | 75 +++++++++++ .../single_op/ctc_greedy_decoder_seq_len.cpp | 124 ++++++++++++++++++ .../src/single_op/ctc_loss.cpp | 92 +++++++++++++ 12 files changed, 495 insertions(+), 50 deletions(-) create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder_seq_len.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/ctc_loss.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder_seq_len.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_loss.hpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder_seq_len.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/ctc_loss.cpp diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp index 3e6cc4ebf2f872..0149a60ba1cb23 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp @@ -2,35 +2,32 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "single_layer_tests/ctc_greedy_decoder.hpp" +#include "single_op_tests/ctc_greedy_decoder.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; -using namespace ngraph::helpers; - namespace { +using ov::test::CTCGreedyDecoderLayerTest; + // Common params -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +const std::vector model_type = { + ov::element::f32, + ov::element::f16 }; std::vector mergeRepeated{true, false}; +std::vector> input_shapes_static = { + {{ 50, 3, 3 }}, + {{ 50, 3, 7 }}, + {{ 50, 3, 8 }}, + {{ 50, 3, 16 }}, + {{ 50, 3, 128 }}, + {{ 50, 3, 49 }}, + {{ 50, 3, 55 }}, + {{ 1, 1, 16 }}}; + const auto basicCases = ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({ 50, 3, 3 }), - std::vector({ 50, 3, 7 }), - std::vector({ 50, 3, 8 }), - std::vector({ 50, 3, 16 }), - std::vector({ 50, 3, 128 }), - std::vector({ 50, 3, 49 }), - std::vector({ 50, 3, 55 }), - std::vector({ 1, 1, 16 })), + ::testing::ValuesIn(model_type), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::ValuesIn(mergeRepeated), ::testing::Values(ov::test::utils::DEVICE_CPU)); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp index 4b843fcb2c941a..bc83d623c8a6b2 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp @@ -2,30 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "single_layer_tests/ctc_greedy_decoder_seq_len.hpp" +#include "single_op_tests/ctc_greedy_decoder_seq_len.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; -using namespace ngraph::helpers; - namespace { +using ov::test::CTCGreedyDecoderSeqLenLayerTest; -std::vector> inputShape{{1, 1, 1}, {1, 6, 10}, {3, 3, 16}, {5, 3, 55}}; +std::vector> shapes1 = {{{1, 1, 1}}, + {{1, 6, 10}}, + {{3, 3, 16}}, + {{5, 3, 55}}}; -const std::vector probPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +const std::vector probPrecisions = { + ov::element::f32, + ov::element::f16 }; -const std::vector idxPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64 +const std::vector idxPrecisions = { + ov::element::i32, + ov::element::i64 }; std::vector mergeRepeated{true, false}; const auto basicCases = ::testing::Combine( - ::testing::ValuesIn(inputShape), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation({shapes1})), ::testing::Values(10), ::testing::ValuesIn(probPrecisions), ::testing::ValuesIn(idxPrecisions), @@ -37,9 +37,12 @@ INSTANTIATE_TEST_SUITE_P(smoke_set1, CTCGreedyDecoderSeqLenLayerTest, basicCases, CTCGreedyDecoderSeqLenLayerTest::getTestCaseName); +std::vector> shapes2 = {{{2, 8, 11}}, + {{4, 10, 55}}}; + INSTANTIATE_TEST_SUITE_P(smoke_set2, CTCGreedyDecoderSeqLenLayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{2, 8, 11}, {4, 10, 55}}), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation({shapes2})), ::testing::ValuesIn(std::vector{5, 100}), ::testing::ValuesIn(probPrecisions), ::testing::ValuesIn(idxPrecisions), diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp index c5da048ce40bc1..45a341a39003d4 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp @@ -4,19 +4,18 @@ #include -#include "single_layer_tests/ctc_loss.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/ctc_loss.hpp" namespace { +using ov::test::CTCLossLayerTest; -const std::vector fPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +const std::vector f_type = { + ov::element::f32, + ov::element::f16 }; -const std::vector iPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64 +const std::vector i_type = { + ov::element::i32, + ov::element::i64 }; const std::vector preprocessCollapseRepeated = {true, false}; @@ -24,7 +23,6 @@ const std::vector ctcMergeRepeated = {true, false}; const std::vector unique = {true, false}; const auto ctcLossArgsSubset1 = ::testing::Combine( - ::testing::Values(std::vector({2, 3, 3})), // logits shape ::testing::ValuesIn(std::vector>({{2, 3}, {3, 3}})), // logits length ::testing::ValuesIn(std::vector>>( {{{0, 1, 0}, {1, 0, 1}}, {{0, 1, 2}, {1, 1, 1}}})), // labels @@ -38,13 +36,13 @@ const auto ctcLossArgsSubset1 = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_Set1, CTCLossLayerTest, ::testing::Combine( ctcLossArgsSubset1, - ::testing::ValuesIn(fPrecisions), - ::testing::ValuesIn(iPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation({{2, 3, 3}})), + ::testing::ValuesIn(f_type), + ::testing::ValuesIn(i_type), ::testing::Values(ov::test::utils::DEVICE_CPU)), CTCLossLayerTest::getTestCaseName); const auto ctcLossArgsSubset2 = ::testing::Combine( - ::testing::Values(std::vector({3, 6, 8})), // logits shape ::testing::ValuesIn(std::vector>({{6, 5, 6}, {5, 5, 5}})), // logits length ::testing::ValuesIn(std::vector>>( {{{4, 1, 2, 3, 4, 5}, {5, 4, 3, 0, 1, 0}, {2, 1, 3, 1, 3, 0}}, @@ -59,8 +57,9 @@ const auto ctcLossArgsSubset2 = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_Set2, CTCLossLayerTest, ::testing::Combine( ctcLossArgsSubset2, - ::testing::ValuesIn(fPrecisions), - ::testing::ValuesIn(iPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation({{3, 6, 8}})), + ::testing::ValuesIn(f_type), + ::testing::ValuesIn(i_type), ::testing::Values(ov::test::utils::DEVICE_CPU)), CTCLossLayerTest::getTestCaseName); } // namespace diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder.hpp new file mode 100644 index 00000000000000..2a3785283f2c14 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/ctc_greedy_decoder.hpp" + +namespace ov { +namespace test { +TEST_P(CTCGreedyDecoderLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder_seq_len.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder_seq_len.hpp new file mode 100644 index 00000000000000..edcb79b3e050f7 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/ctc_greedy_decoder_seq_len.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/ctc_greedy_decoder_seq_len.hpp" + +namespace ov { +namespace test { +TEST_P(CTCGreedyDecoderSeqLenLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/ctc_loss.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/ctc_loss.hpp new file mode 100644 index 00000000000000..43c32bdda6ff80 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/ctc_loss.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/ctc_loss.hpp" + +namespace ov { +namespace test { +TEST_P(CTCLossLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder.hpp new file mode 100644 index 00000000000000..d795bbea676169 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + ov::element::Type, // Model type + std::vector, // Input shapes + bool, // Merge repeated + std::string // Device name +> ctcGreedyDecoderParams; + +class CTCGreedyDecoderLayerTest + : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder_seq_len.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder_seq_len.hpp new file mode 100644 index 00000000000000..46e85ad6fa9260 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_greedy_decoder_seq_len.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // Input shape + int, // Sequence lengths + ov::element::Type, // Probabilities precision + ov::element::Type, // Indices precision + int, // Blank index + bool, // Merge repeated + std::string // Device name + > ctcGreedyDecoderSeqLenParams; + +class CTCGreedyDecoderSeqLenLayerTest + : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_loss.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_loss.hpp new file mode 100644 index 00000000000000..91439cc2c894be --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/ctc_loss.hpp @@ -0,0 +1,43 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // logits length + std::vector>, // labels + std::vector, // labels length + int, // blank index + bool, // preprocessCollapseRepeated + bool, // ctcMergeRepeated + bool // Unique +> CTCLossParamsSubset; + +typedef std::tuple< + CTCLossParamsSubset, + std::vector, // Input shapes + ov::element::Type, // Float point precision + ov::element::Type, // Integer precision + std::string // Device name +> CTCLossParams; + +class CTCLossLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder.cpp b/src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder.cpp new file mode 100644 index 00000000000000..a049952f180253 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder.cpp @@ -0,0 +1,75 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/ctc_greedy_decoder.hpp" + +#include + +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/ctc_greedy_decoder.hpp" + +namespace ov { +namespace test { +std::string CTCGreedyDecoderLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type model_type; + std::vector shapes; + std::string targetDevice; + bool merge_repeated; + std::tie(model_type, shapes, merge_repeated, targetDevice) = obj.param; + + std::ostringstream result; + const char separator = '_'; + + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "netPRC=" << model_type.get_type_name() << separator; + result << "merge_repeated=" << std::boolalpha << merge_repeated << separator; + result << "trgDev=" << targetDevice; + + return result.str(); +} + +void CTCGreedyDecoderLayerTest::SetUp() { + ov::element::Type model_type; + std::vector shapes; + bool merge_repeated; + std::tie(model_type, shapes, merge_repeated, targetDevice) = GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + size_t T = targetStaticShapes[0][0][0]; + size_t B = targetStaticShapes[0][0][1]; + + std::mt19937 gen(1); + std::uniform_int_distribution dist(1, T); + + std::vector sequence_mask_data(B * T, 0); + for (int b = 0; b < B; b++) { + int len = dist(gen); + for (int t = 0; t < len; t++) { + sequence_mask_data[t * B + b] = 1; + } + } + auto sequence_mask_node = std::make_shared(model_type, ov::Shape{T, B}, sequence_mask_data); + + auto ctc_greedy_decoder = std::make_shared(param, sequence_mask_node, merge_repeated); + + auto result = std::make_shared(ctc_greedy_decoder); + function = std::make_shared(result, ov::ParameterVector{param}, "CTCGreedyDecoder"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder_seq_len.cpp b/src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder_seq_len.cpp new file mode 100644 index 00000000000000..1770aff47aae49 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/ctc_greedy_decoder_seq_len.cpp @@ -0,0 +1,124 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/ctc_greedy_decoder_seq_len.hpp" + +#include +#include +#include +#include + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/ctc_greedy_decoder_seq_len.hpp" + +namespace ov { +namespace test { +std::string CTCGreedyDecoderSeqLenLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + int sequenceLengths; + ov::element::Type dataPrecision, indicesPrecision; + int blankIndex; + bool mergeRepeated; + std::string targetDevice; + std::tie(shapes, + sequenceLengths, + dataPrecision, + indicesPrecision, + blankIndex, + mergeRepeated, + targetDevice) = obj.param; + + std::ostringstream result; + + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "seqLen=" << sequenceLengths << '_'; + result << "dataPRC=" << dataPrecision.get_type_name() << '_'; + result << "idxPRC=" << indicesPrecision.get_type_name() << '_'; + result << "BlankIdx=" << blankIndex << '_'; + result << "mergeRepeated=" << std::boolalpha << mergeRepeated << '_'; + result << "trgDev=" << targetDevice; + + return result.str(); +} + +void CTCGreedyDecoderSeqLenLayerTest::SetUp() { + std::vector shapes; + int sequenceLengths; + ov::element::Type model_type, indices_type; + int blankIndex; + bool mergeRepeated; + std::tie(shapes, + sequenceLengths, + model_type, + indices_type, + blankIndex, + mergeRepeated, + targetDevice) = GetParam(); + init_input_shapes(shapes); + + ov::ParameterVector params {std::make_shared(model_type, inputDynamicShapes.front())}; + + const auto sequenceLenNode = [&] { + const size_t B = targetStaticShapes[0][0][0]; + const size_t T = targetStaticShapes[0][0][1]; + + // Cap sequence length up to T + const int seqLen = std::min(T, sequenceLengths); + + std::mt19937 gen{42}; + std::uniform_int_distribution dist(1, seqLen); + + std::vector sequenceLenData(B); + for (int b = 0; b < B; b++) { + const int len = dist(gen); + sequenceLenData[b] = len; + } + + return std::make_shared(indices_type, ov::Shape{B}, sequenceLenData); + }(); + + // Cap blank index up to C - 1 + int C = targetStaticShapes[0][0][2]; + blankIndex = std::min(blankIndex, C - 1); + + const auto blankIndexNode = [&] { + if (indices_type == element::i32) { + const auto blankIdxDataI32 = std::vector{blankIndex}; + return std::make_shared(indices_type, ov::Shape{1}, blankIdxDataI32); + } else if (indices_type == element::i64) { + const auto blankIdxDataI64 = std::vector{blankIndex}; + return std::make_shared(indices_type, ov::Shape{1}, blankIdxDataI64); + } + throw std::logic_error("Unsupported index precision"); + }(); + + auto ctcGreedyDecoderSeqLen = std::make_shared(params[0], + sequenceLenNode, + blankIndexNode, + mergeRepeated, + indices_type, + indices_type); + + ov::OutputVector results; + for (int i = 0; i < ctcGreedyDecoderSeqLen->get_output_size(); i++) { + results.push_back(std::make_shared(ctcGreedyDecoderSeqLen->output(i))); + } + function = std::make_shared(results, params, "CTCGreedyDecoderSeqLen"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/ctc_loss.cpp b/src/tests/functional/shared_test_classes/src/single_op/ctc_loss.cpp new file mode 100644 index 00000000000000..cc4cbbb2fe7eff --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/ctc_loss.cpp @@ -0,0 +1,92 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/ctc_loss.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/ctc_loss.hpp" + +namespace ov { +namespace test { +std::string CTCLossLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type fp_type, int_type; + bool preprocess_collapse_repeated, ctc_merge_repeated, unique; + std::vector logits_length, labels_length; + std::vector> labels; + int blank_index; + std::string targetDevice; + CTCLossParamsSubset ctcLossArgsSubset; + std::tie(ctcLossArgsSubset, shapes, fp_type, int_type, targetDevice) = obj.param; + std::tie(logits_length, labels, labels_length, blank_index, preprocess_collapse_repeated, ctc_merge_repeated, unique) = ctcLossArgsSubset; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "LL=" << ov::test::utils::vec2str(logits_length) << "_"; + result << "A=" << ov::test::utils::vec2str(labels) << "_"; + result << "AL=" << ov::test::utils::vec2str(labels_length) << "_"; + result << "BI=" << blank_index << "_"; + result << "PCR=" << preprocess_collapse_repeated << "_"; + result << "CMR=" << ctc_merge_repeated << "_"; + result << "U=" << unique << "_"; + result << "PF=" << fp_type.get_type_name() << "_"; + result << "PI=" << int_type.get_type_name() << "_"; + result << "targetDevice=" << targetDevice; + return result.str(); +} + +void CTCLossLayerTest::SetUp() { + std::vector shapes; + ov::element::Type fp_type, int_type; + bool preprocess_collapse_repeated, ctc_merge_repeated, unique; + std::vector logits_length, labels_length; + std::vector> labels; + int blank_index; + CTCLossParamsSubset ctcLossArgsSubset; + std::tie(ctcLossArgsSubset, shapes, fp_type, int_type, targetDevice) = this->GetParam(); + std::tie(logits_length, labels, labels_length, blank_index, preprocess_collapse_repeated, + ctc_merge_repeated, unique) = ctcLossArgsSubset; + init_input_shapes(shapes); + + auto param = std::make_shared(fp_type, inputDynamicShapes.front()); + + size_t N = targetStaticShapes[0][0][0]; + size_t T = targetStaticShapes[0][0][1]; + + std::vector labelsOneD(N * T); + for (int i = 0; i < labels.size(); i++) + std::copy(labels[i].begin(), labels[i].end(), labelsOneD.data() + i * T); + + auto logits_length_node = std::make_shared(int_type, ov::Shape{N}, logits_length); + auto labels_node = std::make_shared(int_type, ov::Shape{N, T}, labelsOneD); + auto labels_length_node = std::make_shared(int_type, ov::Shape{N}, labels_length); + auto blank_index_node = std::make_shared(int_type, ov::Shape{}, blank_index); + + auto ctc_loss = std::make_shared(param, + logits_length_node, + labels_node, + labels_length_node, + blank_index_node, + preprocess_collapse_repeated, + ctc_merge_repeated, + unique); + + auto result = std::make_shared(ctc_loss); + function = std::make_shared(result, ov::ParameterVector{param}, "CTCLoss"); +} +} // namespace test +} // namespace ov