[CPU] Native dynamic shapes support in the ReorgYolo node (#8642)

This commit is contained in:
Tingqian Li 2021-11-29 18:31:23 +08:00 committed by GitHub
parent e2ed99a93e
commit b0da652e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 5 deletions

View File

@ -13,10 +13,6 @@ using namespace InferenceEngine;
bool MKLDNNReorgYoloNode::isSupportedOperation(const std::shared_ptr<const ngraph::Node>& op, std::string& errorMessage) noexcept {
try {
if (isDynamicNgraphNode(op)) {
errorMessage = "Doesn't support op with dynamic shapes";
return false;
}
const auto reorgYolo = std::dynamic_pointer_cast<const ngraph::opset2::ReorgYolo>(op);
if (!reorgYolo) {
errorMessage = "Only opset2 ReorgYolo operation is supported";

View File

@ -18,6 +18,10 @@ public:
void createPrimitive() override {};
void execute(mkldnn::stream strm) override;
bool created() const override;
bool needPrepareParams() const override { return false; }
void executeDynamicImpl(mkldnn::stream strm) override {
execute(strm);
}
static bool isSupportedOperation(const std::shared_ptr<const ngraph::Node>& op, std::string& errorMessage) noexcept;

View File

@ -0,0 +1,90 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "functional_test_utils/ov_tensor_utils.hpp"
#include "ngraph_functions/builders.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "test_utils/cpu_test_utils.hpp"
using namespace InferenceEngine;
using namespace CPUTestUtils;
using namespace ngraph::opset3;
using namespace ov::test;
namespace CPULayerTestsDefinitions {
using ReorgYoloCPUParamsTuple = typename std::tuple<InputShape, // Input Shape
size_t, // stride
ElementType, // Network precision
TargetDevice>; // Device
class ReorgYoloLayerCPUTest : public testing::WithParamInterface<ReorgYoloCPUParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<ReorgYoloCPUParamsTuple>& obj) {
InputShape inputShape;
size_t stride;
ElementType netPrecision;
TargetDevice targetDev;
std::tie(inputShape, stride, netPrecision, targetDev) = obj.param;
std::ostringstream result;
result << "IS=" << CommonTestUtils::partialShape2str({inputShape.first}) << "_";
for (const auto& item : inputShape.second) {
result << CommonTestUtils::vec2str(item) << "_";
}
result << "stride=" << stride << "_";
result << "netPRC=" << netPrecision << "_";
result << "targetDevice=" << targetDev << "_";
return result.str();
}
protected:
void SetUp() override {
InputShape inputShape;
size_t stride;
ElementType netPrecision;
std::tie(inputShape, stride, netPrecision, targetDevice) = this->GetParam();
init_input_shapes({inputShape});
auto param = std::make_shared<ngraph::op::Parameter>(ngraph::element::f32, inputDynamicShapes[0]);
auto reorg_yolo = std::make_shared<ngraph::op::v0::ReorgYolo>(param, stride);
function = std::make_shared<ngraph::Function>(std::make_shared<ngraph::opset1::Result>(reorg_yolo),
ngraph::ParameterVector{param},
"ReorgYolo");
}
};
TEST_P(ReorgYoloLayerCPUTest, CompareWithRefs) {
run();
};
const std::vector<ov::test::InputShape> inShapesDynamic = {
{{{1, 2}, -1, -1, -1}, {{1, 4, 4, 4}, {1, 8, 4, 4}, {2, 8, 4, 4}}}};
const std::vector<size_t> strides = {2, 3};
const std::vector<ov::test::InputShape> inShapesDynamic2 = {{{{1, 2}, -1, -1, -1}, {{1, 9, 3, 3}}}};
const auto testCase_stride2_Dynamic = ::testing::Combine(::testing::ValuesIn(inShapesDynamic),
::testing::Values(strides[0]),
::testing::Values(ov::element::f32),
::testing::Values(CommonTestUtils::DEVICE_CPU));
const auto testCase_stride3_Dynamic = ::testing::Combine(::testing::ValuesIn(inShapesDynamic2),
::testing::Values(strides[1]),
::testing::Values(ov::element::f32),
::testing::Values(CommonTestUtils::DEVICE_CPU));
INSTANTIATE_TEST_SUITE_P(smoke_TestsReorgYolo_stride2_DynamicShape,
ReorgYoloLayerCPUTest,
testCase_stride2_Dynamic,
ReorgYoloLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsReorgYolo_stride3_DynamicShape,
ReorgYoloLayerCPUTest,
testCase_stride3_Dynamic,
ReorgYoloLayerCPUTest::getTestCaseName);
}; // namespace CPULayerTestsDefinitions

View File

@ -50,7 +50,8 @@ void op::ReorgYolo::validate_and_infer_types() {
}
set_output_type(0, input_et, output_shape);
} else {
set_output_type(0, input_et, ov::PartialShape::dynamic());
auto input_shape = get_input_partial_shape(0);
set_output_type(0, input_et, ov::PartialShape::dynamic(input_shape.rank()));
}
}