[CPU] Dynamism support for RegionYolo node (#8542)

This commit is contained in:
Edward Shogulin
2021-12-01 10:18:03 +03:00
committed by GitHub
parent ae633c5b2d
commit 9ec7bf286e
4 changed files with 109 additions and 35 deletions

View File

@@ -229,10 +229,6 @@ private:
bool MKLDNNRegionYoloNode::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 regionYolo = std::dynamic_pointer_cast<const ngraph::opset1::RegionYolo>(op);
if (!regionYolo) {
errorMessage = "Only opset1 RegionYolo operation is supported";
@@ -244,6 +240,10 @@ bool MKLDNNRegionYoloNode::isSupportedOperation(const std::shared_ptr<const ngra
return true;
}
bool MKLDNNRegionYoloNode::needPrepareParams() const {
return false;
}
MKLDNNRegionYoloNode::MKLDNNRegionYoloNode(const std::shared_ptr<ngraph::Node>& op, const mkldnn::engine& eng,
MKLDNNWeightsSharing::Ptr &cache) : MKLDNNNode(op, eng, cache) {
std::string errorMessage;
@@ -302,6 +302,10 @@ void MKLDNNRegionYoloNode::initSupportedPrimitiveDescriptors() {
}
void MKLDNNRegionYoloNode::createPrimitive() {
if (inputShapesDefined()) {
updateLastInputDims();
}
jit_logistic_config_params jcp;
jcp.src_dt = jcp.dst_dt = output_prec;
jcp.src_data_size = jcp.dst_data_size = output_prec.size();

View File

@@ -49,6 +49,10 @@ public:
static bool isSupportedOperation(const std::shared_ptr<const ngraph::Node>& op, std::string& errorMessage) noexcept;
protected:
bool needPrepareParams() const override;
void executeDynamicImpl(mkldnn::stream strm) override { execute(strm); }
private:
int classes;
int coords;

View File

@@ -4,11 +4,13 @@
#include "ngraph_functions/builders.hpp"
#include "test_utils/cpu_test_utils.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
using namespace InferenceEngine;
using namespace CPUTestUtils;
namespace CPULayerTestsDefinitions {
using namespace ov::test;
struct regionYoloAttributes {
size_t classes;
@@ -20,78 +22,86 @@ struct regionYoloAttributes {
};
using regionYoloParamsTuple = std::tuple<
ngraph::Shape, // Input Shape
regionYoloAttributes, // Params
InputShape, // Input Shape
regionYoloAttributes, // Params
std::vector<int64_t>, // mask
InferenceEngine::Precision, // Network input precision
InferenceEngine::Precision, // Network output precision
ov::test::ElementType, // Network input precision
ov::test::ElementType, // Network output precision
std::map<std::string, std::string>, // Additional network configuration
std::string>; // Device name
class RegionYoloCPULayerTest : public testing::WithParamInterface<regionYoloParamsTuple>,
virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase {
virtual public ov::test::SubgraphBaseTest, public CPUTestsBase {
public:
static std::string getTestCaseName(testing::TestParamInfo<regionYoloParamsTuple> obj) {
ngraph::Shape inputShape;
InputShape inputShape;
regionYoloAttributes attributes;
std::vector<int64_t> mask;
InferenceEngine::Precision inpPrecision;
InferenceEngine::Precision outPrecision;
ov::test::ElementType inpPrecision;
ov::test::ElementType outPrecision;
std::string targetName;
std::map<std::string, std::string> additionalConfig;
std::tie(inputShape, attributes, mask, inpPrecision, outPrecision, additionalConfig, targetName) = obj.param;
std::ostringstream result;
result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_";
result << "IS=" << inputShape << "_";
result << "classes=" << attributes.classes << "_";
result << "coords=" << attributes.coordinates << "_";
result << "num=" << attributes.num_regions << "_";
result << "doSoftmax=" << attributes.do_softmax << "_";
result << "axis=" << attributes.start_axis << "_";
result << "endAxis=" << attributes.end_axis << "_";
result << "inpPRC=" << inpPrecision.name() << "_";
result << "outPRC=" << outPrecision.name() << "_";
result << "inpPRC=" << inpPrecision << "_";
result << "outPRC=" << outPrecision << "_";
result << "targetDevice=" << targetName << "_";
return result.str();
}
protected:
void SetUp() override {
ngraph::Shape inputShape;
InputShape inputShape;
regionYoloAttributes attributes;
std::vector<int64_t> mask;
ov::test::ElementType inPrc;
ov::test::ElementType outPrc;
std::map<std::string, std::string> additionalConfig;
std::tie(inputShape, attributes, mask, inPrc, outPrc, additionalConfig, targetDevice) = this->GetParam();
if (inPrc == ov::test::ElementType::bf16) {
// ticket #72342
rel_threshold = 0.02;
}
init_input_shapes({ inputShape });
configuration.insert(additionalConfig.begin(), additionalConfig.end());
selectedType = getPrimitiveType() + "_" + inPrc.name();
const auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inPrc);
auto paramRegionYolo = ngraph::builder::makeParams(ngPrc, {inputShape});
selectedType = getPrimitiveType() + "_" + InferenceEngine::details::convertPrecision(inPrc).name();
auto paramRegionYolo = ngraph::builder::makeDynamicParams(inPrc, inputDynamicShapes);
const auto region_yolo = std::make_shared<ngraph::op::v0::RegionYolo>(paramRegionYolo[0],
attributes.coordinates, attributes.classes, attributes.num_regions,
attributes.do_softmax, mask, attributes.start_axis, attributes.end_axis);
function = makeNgraphFunction(ngPrc, paramRegionYolo, region_yolo, "RegionYolo");
function = makeNgraphFunction(inPrc, paramRegionYolo, region_yolo, "RegionYolo");
}
};
TEST_P(RegionYoloCPULayerTest, CompareWithRefs) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
Run();
run();
CheckPluginRelatedResults(executableNetwork, "RegionYolo");
}
namespace {
const std::vector<Precision> inpOutPrc = {Precision::BF16, Precision::FP32};
const std::vector<ov::test::ElementType> inpOutPrc = {ov::test::ElementType::bf16, ov::test::ElementType::f32};
const std::map<std::string, std::string> additional_config;
/* *======================* Static Shapes *======================* */
const std::vector<ngraph::Shape> inShapes_caffe = {
{1, 125, 13, 13}
};
@@ -114,6 +124,24 @@ const std::vector<ngraph::Shape> inShapes_v3 = {
{1, 255, 13, 13}
};
/* *======================* Dynamic Shapes *======================* */
const std::vector<InputShape> inShapes_caffe_dynamic = {
{{-1, -1, -1, -1}, {{1, 125, 13, 13}, {1, 125, 26, 26}}},
{{{1, 2}, {100, 125}, {13, 26}, {13, 26}}, {{1, 125, 13, 13}, {1, 125, 26, 26}}}
};
const std::vector<InputShape> inShapes_mxnet_dynamic = {
{{-1, -1, -1, -1}, {{1, 75, 52, 52}, {1, 75, 32, 32}, {1, 75, 26, 26}}},
{{{1, 2}, {75, 80}, {26, 52}, {26, 52}}, {{1, 75, 52, 52}, {1, 75, 32, 32}, {1, 75, 26, 26}}},
};
const std::vector<InputShape> inShapes_v3_dynamic = {
{{-1, -1, -1, -1}, {{1, 255, 52, 52}, {1, 255, 26, 26}, {1, 255, 13, 13}}},
{{{1, 2}, {255, 256}, {13, 52}, {13, 52}}, {{1, 255, 52, 52}, {1, 255, 26, 26}, {1, 255, 13, 13}}}
};
const std::vector<std::vector<int64_t>> masks = {
{0, 1, 2},
{3, 4, 5},
@@ -127,7 +155,17 @@ const std::vector<size_t> num_regions = {5, 9};
const regionYoloAttributes yoloV3attr = {80, 4, 9, false, 1, 3};
const auto testCase_yolov3 = ::testing::Combine(
::testing::ValuesIn(inShapes_v3),
::testing::ValuesIn(static_shapes_to_test_representation(inShapes_v3)),
::testing::Values(yoloV3attr),
::testing::Values(masks[2]),
::testing::ValuesIn(inpOutPrc),
::testing::ValuesIn(inpOutPrc),
::testing::Values(additional_config),
::testing::Values(CommonTestUtils::DEVICE_CPU)
);
const auto testCase_yolov3_dynamic = ::testing::Combine(
::testing::ValuesIn(inShapes_v3_dynamic),
::testing::Values(yoloV3attr),
::testing::Values(masks[2]),
::testing::ValuesIn(inpOutPrc),
@@ -139,7 +177,17 @@ const auto testCase_yolov3 = ::testing::Combine(
const regionYoloAttributes yoloV3mxnetAttr = {20, 4, 9, false, 1, 3};
const auto testCase_yolov3_mxnet = ::testing::Combine(
::testing::ValuesIn(inShapes_mxnet),
::testing::ValuesIn(static_shapes_to_test_representation(inShapes_mxnet)),
::testing::Values(yoloV3mxnetAttr),
::testing::Values(masks[1]),
::testing::ValuesIn(inpOutPrc),
::testing::ValuesIn(inpOutPrc),
::testing::Values(additional_config),
::testing::Values(CommonTestUtils::DEVICE_CPU)
);
const auto testCase_yolov3_mxnet_dynamic = ::testing::Combine(
::testing::ValuesIn(inShapes_mxnet_dynamic),
::testing::Values(yoloV3mxnetAttr),
::testing::Values(masks[1]),
::testing::ValuesIn(inpOutPrc),
@@ -151,7 +199,7 @@ const auto testCase_yolov3_mxnet = ::testing::Combine(
const regionYoloAttributes yoloV2caffeAttr = {20, 4, 5, true, 1, 3};
const auto testCase_yolov2_caffe = ::testing::Combine(
::testing::ValuesIn(inShapes_caffe),
::testing::ValuesIn(static_shapes_to_test_representation(inShapes_caffe)),
::testing::Values(yoloV2caffeAttr),
::testing::Values(masks[0]),
::testing::ValuesIn(inpOutPrc),
@@ -160,8 +208,21 @@ const auto testCase_yolov2_caffe = ::testing::Combine(
::testing::Values(CommonTestUtils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYolov3CPU, RegionYoloCPULayerTest, testCase_yolov3, RegionYoloCPULayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYoloMxnetCPU, RegionYoloCPULayerTest, testCase_yolov3_mxnet, RegionYoloCPULayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYoloCaffeCPU, RegionYoloCPULayerTest, testCase_yolov2_caffe, RegionYoloCPULayerTest::getTestCaseName);
const auto testCase_yolov2_caffe_dynamic = ::testing::Combine(
::testing::ValuesIn(inShapes_caffe_dynamic),
::testing::Values(yoloV2caffeAttr),
::testing::Values(masks[0]),
::testing::ValuesIn(inpOutPrc),
::testing::ValuesIn(inpOutPrc),
::testing::Values(additional_config),
::testing::Values(CommonTestUtils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYolov3CPUStatic, RegionYoloCPULayerTest, testCase_yolov3, RegionYoloCPULayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYolov3CPUDynamic, RegionYoloCPULayerTest, testCase_yolov3_dynamic, RegionYoloCPULayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYoloMxnetCPUStatic, RegionYoloCPULayerTest, testCase_yolov3_mxnet, RegionYoloCPULayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYoloMxnetCPUDynamic, RegionYoloCPULayerTest, testCase_yolov3_mxnet_dynamic, RegionYoloCPULayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYoloCaffeCPUStatic, RegionYoloCPULayerTest, testCase_yolov2_caffe, RegionYoloCPULayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsRegionYoloCaffeCPUDynamic, RegionYoloCPULayerTest, testCase_yolov2_caffe_dynamic, RegionYoloCPULayerTest::getTestCaseName);
} // namespace
} // namespace CPULayerTestsDefinitions

View File

@@ -55,9 +55,10 @@ void op::RegionYolo::validate_and_infer_types() {
"Type of input is expected to be a floating point type. Got: ",
input_et);
if (get_input_partial_shape(0).is_static()) {
ov::Shape input_shape = get_input_partial_shape(0).to_shape();
ov::Shape output_shape;
const auto& input_partial_shape = get_input_partial_shape(0);
if (input_partial_shape.rank().is_static()) {
ov::PartialShape input_shape = get_input_partial_shape(0);
ov::PartialShape output_shape;
int end_axis = m_end_axis;
if (m_end_axis < 0) {
m_end_axis += input_shape.size();
@@ -69,7 +70,11 @@ void op::RegionYolo::validate_and_infer_types() {
output_shape.push_back(input_shape[i]);
}
for (int64_t i = m_axis; i < end_axis + 1; i++) {
flat_dim *= input_shape[i];
if (input_shape[i].is_dynamic()) {
flat_dim = -1;
break;
}
flat_dim *= input_shape[i].get_length();
}
output_shape.push_back(flat_dim);
for (size_t i = end_axis + 1; i < input_shape.size(); i++) {
@@ -77,7 +82,7 @@ void op::RegionYolo::validate_and_infer_types() {
}
} else {
output_shape = {input_shape[0],
(m_num_classes + m_num_coords + 1) * m_mask.size(),
ov::Dimension((m_num_classes + m_num_coords + 1) * m_mask.size()),
input_shape[2],
input_shape[3]};
}