Review CTCLoss class for shape inference aspects (#15375)

* Review ctc loss operator for
- partial shape and label propagation
- template implementation of shape_infer
- update/extend tests

* Use namespace ov in ctc loss operator
This commit is contained in:
Pawel Raasz authored and GitHub committed 2023-01-31 14:10:30 +04:00
1 parent 3a8646215f
commit 4ce3e9a88d
5 files changed
+293 -350

No files matched your search

@@ -1,35 +0,0 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include <ctc_loss_shape_inference.hpp>
#include <openvino/op/ctc_loss.hpp>
#include <openvino/op/parameter.hpp>
#include <utils/shape_inference/shape_inference.hpp>
#include <utils/shape_inference/static_shape.hpp>
using namespace ov;
using namespace ov::intel_cpu;
TEST(StaticShapeInferenceTest, CTCLossTest) {
const auto& logits = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1});
const auto& logit_length = std::make_shared<ov::op::v0::Parameter>(element::i32, PartialShape{-1});
const auto& labels = std::make_shared<ov::op::v0::Parameter>(element::i32, PartialShape{-1, -1});
const auto& label_length = std::make_shared<ov::op::v0::Parameter>(element::i32, PartialShape{-1});
const auto& blank_index = std::make_shared<ov::op::v0::Parameter>(element::i32, ov::Shape{});
// create CTCLoss node
auto ctc_loss = std::make_shared<op::v4::CTCLoss>(logits, logit_length, labels, label_length, blank_index);
std::vector<StaticShape> static_input_shapes = {StaticShape{10, 120, 28},
StaticShape{10},
StaticShape{10, 120},
StaticShape{10},
ov::Shape{}},
static_output_shapes = {StaticShape{}};
shape_inference(ctc_loss.get(), static_input_shapes, static_output_shapes);
ASSERT_EQ(static_output_shapes[0], StaticShape({10}));
}
@@ -0,0 +1,46 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "ctc_loss_shape_inference.hpp"
#include "openvino/opsets/opset10.hpp"
#include "utils.hpp"
using namespace ov;
using namespace ov::opset10;
using namespace ov::intel_cpu;
class CTCLossV4StaticShapeInferenceTest : public OpStaticShapeInferenceTest<op::v4::CTCLoss> {
protected:
void SetUp() override {
output_shapes.resize(1);
}
};
TEST_F(CTCLossV4StaticShapeInferenceTest, correct_input_shapes) {
const auto& logits = std::make_shared<Parameter>(element::f32, PartialShape{-1, -1, -1});
const auto& logit_length = std::make_shared<Parameter>(element::i32, PartialShape{-1});
const auto& labels = std::make_shared<Parameter>(element::i32, PartialShape{-1, -1});
const auto& label_length = std::make_shared<Parameter>(element::i32, PartialShape{-1});
const auto& blank_index = std::make_shared<Parameter>(element::i32, ov::Shape{});
auto op = make_op(logits, logit_length, labels, label_length, blank_index);
input_shapes = ShapeVector{{10, 120, 28}, {10}, {10, 120}, {10}, {}};
shape_inference(op.get(), input_shapes, output_shapes);
EXPECT_EQ(output_shapes.size(), 1);
EXPECT_EQ(output_shapes.front(), StaticShape({10}));
}
TEST_F(CTCLossV4StaticShapeInferenceTest, default_ctor) {
auto op = make_op();
input_shapes = ShapeVector{{12, 120, 28}, {12}, {12, 120}, {12}, {}};
shape_inference(op.get(), input_shapes, output_shapes);
EXPECT_EQ(output_shapes.size(), 1);
EXPECT_EQ(output_shapes.front(), StaticShape({12}));
}