Migrate ngraph backend test/prior box (#8227)

* Remove fp16 of Convert layer test from skip_tests.config.cpp as it works now

* update repo

* add op reference test of prior_box/prior_box_clustered/reorg_yolo and remove ngraph backend test

* remove related backend test file
This commit is contained in:
Wilson Seok 2021-11-10 04:28:41 -08:00 committed by GitHub
parent a788dc31e2
commit 35ba404bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 383 additions and 196 deletions

View File

@ -0,0 +1,126 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/op/prior_box.hpp"
#include "base_reference_test.hpp"
#include "openvino/opsets/opset1.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct PriorBoxParams {
template <class IT>
PriorBoxParams(const std::vector<float>& min_size,
const std::vector<float>& aspect_ratio,
const bool scale_all_size,
const ov::Shape& layerShapeShape, const ov::Shape& imageShapeShape,
const ov::element::Type& iType,
const std::vector<IT>& layerShapeValues, const std::vector<IT>& imageShapeValues,
const std::vector<float>& oValues,
const std::string& testcaseName = "")
: layerShapeShape(layerShapeShape),
imageShapeShape(imageShapeShape),
inType(iType),
outType(ov::element::Type_t::f32),
layerShapeData(CreateTensor(iType, layerShapeValues)),
imageShapeData(CreateTensor(iType, imageShapeValues)),
refData(CreateTensor(outType, oValues)),
testcaseName(testcaseName) {
attrs.min_size = min_size;
attrs.aspect_ratio = aspect_ratio;
attrs.scale_all_sizes = scale_all_size;
}
ov::op::v0::PriorBox::Attributes attrs;
ov::Shape layerShapeShape;
ov::Shape imageShapeShape;
ov::element::Type inType;
ov::element::Type outType;
ov::runtime::Tensor layerShapeData;
ov::runtime::Tensor imageShapeData;
ov::runtime::Tensor refData;
std::string testcaseName;
};
class ReferencePriorBoxLayerTest : public testing::TestWithParam<PriorBoxParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {};
refOutData = {params.refData};
}
static std::string getTestCaseName(const testing::TestParamInfo<PriorBoxParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "layerShapeShape=" << param.layerShapeShape << "_";
result << "imageShapeShape=" << param.imageShapeShape << "_";
result << "iType=" << param.inType << "_";
result << "oType=" << param.outType;
if (param.testcaseName != "")
result << "_" << param.testcaseName;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const PriorBoxParams& params) {
auto LS = std::make_shared<opset1::Constant>(params.inType, params.layerShapeShape, params.layerShapeData.data());
auto IS = std::make_shared<opset1::Constant>(params.inType, params.imageShapeShape, params.imageShapeData.data());
const auto PriorBox = std::make_shared<op::v0::PriorBox>(LS, IS, params.attrs);
return std::make_shared<ov::Function>(NodeVector {PriorBox}, ParameterVector {});
}
};
TEST_P(ReferencePriorBoxLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<PriorBoxParams> generatePriorBoxFloatParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<PriorBoxParams> priorBoxParams {
PriorBoxParams({2.0f}, {1.5f}, false,
{2}, {2},
IN_ET,
std::vector<T>{2, 2},
std::vector<T>{10, 10},
std::vector<float>{-0.75, -0.75, 1.25, 1.25, -0.974745, -0.566497, 1.47474, 1.0665,
-0.25, -0.75, 1.75, 1.25, -0.474745, -0.566497, 1.97474, 1.0665,
-0.75, -0.25, 1.25, 1.75, -0.974745, -0.0664966, 1.47474, 1.5665,
-0.25, -0.25, 1.75, 1.75, -0.474745, -0.0664966, 1.97474, 1.5665,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}),
};
return priorBoxParams;
}
std::vector<PriorBoxParams> generatePriorBoxCombinedParams() {
const std::vector<std::vector<PriorBoxParams>> priorBoxTypeParams {
generatePriorBoxFloatParams<element::Type_t::i64>(),
generatePriorBoxFloatParams<element::Type_t::i32>(),
generatePriorBoxFloatParams<element::Type_t::i16>(),
generatePriorBoxFloatParams<element::Type_t::i8>(),
generatePriorBoxFloatParams<element::Type_t::u64>(),
generatePriorBoxFloatParams<element::Type_t::u32>(),
generatePriorBoxFloatParams<element::Type_t::u16>(),
generatePriorBoxFloatParams<element::Type_t::u8>(),
};
std::vector<PriorBoxParams> combinedParams;
for (const auto& params : priorBoxTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_PriorBox_With_Hardcoded_Refs, ReferencePriorBoxLayerTest,
testing::ValuesIn(generatePriorBoxCombinedParams()), ReferencePriorBoxLayerTest::getTestCaseName);
} // namespace

View File

@ -0,0 +1,134 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/op/prior_box.hpp"
#include "base_reference_test.hpp"
#include "openvino/opsets/opset1.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct PriorBoxClusteredParams {
template <class IT>
PriorBoxClusteredParams(const std::vector<float>& widths,
const std::vector<float>& heights,
const bool clip,
const ov::Shape& layerShapeShape, const ov::Shape& imageShapeShape,
const ov::element::Type& iType,
const std::vector<IT>& layerShapeValues, const std::vector<IT>& imageShapeValues,
const std::vector<float>& oValues,
const std::vector<float>& variances = {},
const std::string& testcaseName = "")
: layerShapeShape(layerShapeShape),
imageShapeShape(imageShapeShape),
inType(iType),
outType(ov::element::Type_t::f32),
layerShapeData(CreateTensor(iType, layerShapeValues)),
imageShapeData(CreateTensor(iType, imageShapeValues)),
refData(CreateTensor(outType, oValues)),
testcaseName(testcaseName) {
attrs.widths = widths;
attrs.heights = heights;
attrs.clip = clip;
if ( variances.size() != 0)
attrs.variances = variances;
}
ov::op::v0::PriorBoxClustered::Attributes attrs;
ov::Shape layerShapeShape;
ov::Shape imageShapeShape;
ov::element::Type inType;
ov::element::Type outType;
ov::runtime::Tensor layerShapeData;
ov::runtime::Tensor imageShapeData;
ov::runtime::Tensor refData;
std::string testcaseName;
};
class ReferencePriorBoxClusteredLayerTest : public testing::TestWithParam<PriorBoxClusteredParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {};
refOutData = {params.refData};
}
static std::string getTestCaseName(const testing::TestParamInfo<PriorBoxClusteredParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "layerShapeShape=" << param.layerShapeShape << "_";
result << "imageShapeShape=" << param.imageShapeShape << "_";
result << "variancesSize=" << param.attrs.variances.size() << "_";
result << "iType=" << param.inType << "_";
result << "oType=" << param.outType;
if (param.testcaseName != "")
result << "_" << param.testcaseName;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const PriorBoxClusteredParams& params) {
auto LS = std::make_shared<opset1::Constant>(params.inType, params.layerShapeShape, params.layerShapeData.data());
auto IS = std::make_shared<opset1::Constant>(params.inType, params.imageShapeShape, params.imageShapeData.data());
const auto PriorBoxClustered = std::make_shared<op::v0::PriorBoxClustered>(LS, IS, params.attrs);
return std::make_shared<ov::Function>(NodeVector {PriorBoxClustered}, ParameterVector {});
}
};
TEST_P(ReferencePriorBoxClusteredLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<PriorBoxClusteredParams> generatePriorBoxClusteredFloatParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<PriorBoxClusteredParams> priorBoxClusteredParams {
PriorBoxClusteredParams({3.0f}, {3.0f}, true,
{2}, {2},
IN_ET,
std::vector<T>{2, 2},
std::vector<T>{10, 10},
std::vector<float>{0, 0, 0.15f, 0.15f, 0.34999f, 0, 0.64999f, 0.15f, 0, 0.34999f, 0.15f,
0.64999f, 0.34999f, 0.34999f, 0.64999f, 0.64999f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f,
0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f}),
PriorBoxClusteredParams({3.0f}, {3.0f}, true,
{2}, {2},
IN_ET,
std::vector<T>{2, 2},
std::vector<T>{10, 10},
std::vector<float>{0, 0, 0.15f, 0.15f, 0.34999f, 0, 0.64999f, 0.15f, 0, 0.34999f, 0.15f,
0.64999f, 0.34999f, 0.34999f, 0.64999f, 0.64999f, 0.1f, 0.2f, 0.3f, 0.4f, 0.1f, 0.2f,
0.3f, 0.4f, 0.1f, 0.2f, 0.3f, 0.4f, 0.1f, 0.2f, 0.3f, 0.4f},
{0.1f, 0.2f, 0.3f, 0.4f}),
};
return priorBoxClusteredParams;
}
std::vector<PriorBoxClusteredParams> generatePriorBoxClusteredCombinedParams() {
const std::vector<std::vector<PriorBoxClusteredParams>> priorBoxClusteredTypeParams {
generatePriorBoxClusteredFloatParams<element::Type_t::i64>(),
generatePriorBoxClusteredFloatParams<element::Type_t::i32>(),
generatePriorBoxClusteredFloatParams<element::Type_t::i16>(),
generatePriorBoxClusteredFloatParams<element::Type_t::i8>(),
generatePriorBoxClusteredFloatParams<element::Type_t::u64>(),
generatePriorBoxClusteredFloatParams<element::Type_t::u32>(),
generatePriorBoxClusteredFloatParams<element::Type_t::u16>(),
generatePriorBoxClusteredFloatParams<element::Type_t::u8>(),
};
std::vector<PriorBoxClusteredParams> combinedParams;
for (const auto& params : priorBoxClusteredTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_PriorBoxClustered_With_Hardcoded_Refs, ReferencePriorBoxClusteredLayerTest,
testing::ValuesIn(generatePriorBoxClusteredCombinedParams()), ReferencePriorBoxClusteredLayerTest::getTestCaseName);
} // namespace

View File

@ -0,0 +1,123 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/op/reorg_yolo.hpp"
#include "base_reference_test.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct ReorgYoloParams {
template <class IT>
ReorgYoloParams(const ov::Strides& stride,
const ov::PartialShape& inputShape,
const ov::element::Type& iType,
const std::vector<IT>& oValues,
const std::string& testcaseName = "")
: stride(stride),
inputShape(inputShape),
inType(iType),
outType(iType),
refData(CreateTensor(iType, oValues)),
testcaseName(testcaseName) {
std::vector<IT> iValues(shape_size(inputShape.get_shape()));
std::iota(iValues.begin(), iValues.end(), 0);
inputData = CreateTensor(iType, iValues);
}
ov::Strides stride;
ov::PartialShape inputShape;
ov::element::Type inType;
ov::element::Type outType;
ov::runtime::Tensor inputData;
ov::runtime::Tensor refData;
std::string testcaseName;
};
class ReferenceReorgYoloLayerTest : public testing::TestWithParam<ReorgYoloParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.inputData};
refOutData = {params.refData};
}
static std::string getTestCaseName(const testing::TestParamInfo<ReorgYoloParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "inputShape=" << param.inputShape << "_";
result << "iType=" << param.inType << "_";
result << "oType=" << param.outType << "_";
result << "stride=" << param.stride;
if (param.testcaseName != "")
result << "_" << param.testcaseName;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const ReorgYoloParams& params) {
const auto p = std::make_shared<op::v0::Parameter>(params.inType, params.inputShape);
const auto ReorgYolo = std::make_shared<op::v0::ReorgYolo>(p, params.stride);
return std::make_shared<ov::Function>(NodeVector {ReorgYolo}, ParameterVector {p});
}
};
TEST_P(ReferenceReorgYoloLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<ReorgYoloParams> generateReorgYoloParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<ReorgYoloParams> reorgYoloParams {
ReorgYoloParams({2},
PartialShape {1, 8, 4, 4},
IN_ET,
std::vector<T>{0, 2, 4, 6, 16, 18, 20, 22, 32, 34, 36, 38, 48, 50, 52, 54, 64, 66, 68, 70, 80, 82,
84, 86, 96, 98, 100, 102, 112, 114, 116, 118, 1, 3, 5, 7, 17, 19, 21, 23, 33, 35, 37, 39,
49, 51, 53, 55, 65, 67, 69, 71, 81, 83, 85, 87, 97, 99, 101, 103, 113, 115, 117, 119, 8, 10,
12, 14, 24, 26, 28, 30, 40, 42, 44, 46, 56, 58, 60, 62, 72, 74, 76, 78, 88, 90, 92, 94,
104, 106, 108, 110, 120, 122, 124, 126, 9, 11, 13, 15, 25, 27, 29, 31, 41, 43, 45, 47, 57, 59,
61, 63, 73, 75, 77, 79, 89, 91, 93, 95, 105, 107, 109, 111, 121, 123, 125, 127}),
ReorgYoloParams({3},
PartialShape {1, 9, 3, 3},
IN_ET,
std::vector<T>{0, 3, 6, 27, 30, 33, 54, 57, 60, 1, 4, 7, 28, 31, 34, 55, 58, 61, 2, 5, 8, 29, 32, 35, 56, 59, 62,
9, 12, 15, 36, 39, 42, 63, 66, 69, 10, 13, 16, 37, 40, 43, 64, 67, 70, 11, 14, 17, 38, 41, 44, 65, 68, 71,
18, 21, 24, 45, 48, 51, 72, 75, 78, 19, 22, 25, 46, 49, 52, 73, 76, 79, 20, 23, 26, 47, 50, 53, 74, 77, 80}),
};
return reorgYoloParams;
}
std::vector<ReorgYoloParams> generateReorgYoloCombinedParams() {
const std::vector<std::vector<ReorgYoloParams>> reorgYoloTypeParams {
generateReorgYoloParams<element::Type_t::f64>(),
generateReorgYoloParams<element::Type_t::f32>(),
generateReorgYoloParams<element::Type_t::f16>(),
generateReorgYoloParams<element::Type_t::bf16>(),
generateReorgYoloParams<element::Type_t::i64>(),
generateReorgYoloParams<element::Type_t::i32>(),
generateReorgYoloParams<element::Type_t::i16>(),
generateReorgYoloParams<element::Type_t::i8>(),
generateReorgYoloParams<element::Type_t::u64>(),
generateReorgYoloParams<element::Type_t::u32>(),
generateReorgYoloParams<element::Type_t::u16>(),
generateReorgYoloParams<element::Type_t::u8>(),
};
std::vector<ReorgYoloParams> combinedParams;
for (const auto& params : reorgYoloTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_ReorgYolo_With_Hardcoded_Refs, ReferenceReorgYoloLayerTest,
testing::ValuesIn(generateReorgYoloCombinedParams()), ReferenceReorgYoloLayerTest::getTestCaseName);
} // namespace

View File

@ -494,11 +494,8 @@ set(MULTI_TEST_SRC
backend/non_max_suppression.in.cpp
backend/one_hot.in.cpp
backend/pad.in.cpp
backend/prior_box_clustered.in.cpp
backend/prior_box.in.cpp
backend/recurrent_cells.in.cpp
backend/region_yolo.in.cpp
backend/reorg_yolo.in.cpp
backend/roll.in.cpp
backend/space_to_depth.in.cpp
backend/shuffle_channels.in.cpp

View File

@ -1,44 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/op/prior_box.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, prior_box) {
op::PriorBoxAttrs attrs;
attrs.min_size = {2.0f};
attrs.aspect_ratio = {1.5f};
attrs.scale_all_sizes = false;
Shape layer_shape_shape{2};
Shape image_shape_shape{2};
vector<int64_t> layer_shape{2, 2};
vector<int64_t> image_shape{10, 10};
auto LS = op::Constant::create(element::i64, layer_shape_shape, layer_shape);
auto IS = op::Constant::create(element::i64, image_shape_shape, image_shape);
auto f = make_shared<Function>(make_shared<op::PriorBox>(LS, IS, attrs), ParameterVector{});
const auto exp_shape = Shape{2, 32};
vector<float> out{-0.75, -0.75, 1.25, 1.25, -0.974745, -0.566497, 1.47474, 1.0665,
-0.25, -0.75, 1.75, 1.25, -0.474745, -0.566497, 1.97474, 1.0665,
-0.75, -0.25, 1.25, 1.75, -0.974745, -0.0664966, 1.47474, 1.5665,
-0.25, -0.25, 1.75, 1.75, -0.474745, -0.0664966, 1.97474, 1.5665,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_expected_output<float>(exp_shape, out);
test_case.run_with_tolerance_as_fp(1.0e-5f);
}

View File

@ -1,65 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/op/prior_box_clustered.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, prior_box_clustered) {
op::PriorBoxClusteredAttrs attrs;
attrs.widths = {3.0f};
attrs.heights = {3.0f};
attrs.clip = true;
Shape layer_shape_shape{2};
Shape image_shape_shape{2};
vector<int64_t> layer_shape{2, 2};
vector<int64_t> image_shape{10, 10};
auto LS = op::Constant::create(element::i64, layer_shape_shape, layer_shape);
auto IS = op::Constant::create(element::i64, image_shape_shape, image_shape);
auto f = make_shared<Function>(make_shared<op::PriorBoxClustered>(LS, IS, attrs), ParameterVector{});
const auto exp_shape = Shape{2, 16};
vector<float> out{0, 0, 0.15f, 0.15f, 0.34999f, 0, 0.64999f, 0.15f, 0, 0.34999f, 0.15f,
0.64999f, 0.34999f, 0.34999f, 0.64999f, 0.64999f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f,
0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_expected_output<float>(exp_shape, out);
test_case.run_with_tolerance_as_fp(1.0e-5f);
}
NGRAPH_TEST(${BACKEND_NAME}, prior_box_clustered_non_default_variances) {
op::PriorBoxClusteredAttrs attrs;
attrs.widths = {3.0f};
attrs.heights = {3.0f};
attrs.clip = true;
attrs.variances = {0.1f, 0.2f, 0.3f, 0.4f};
Shape layer_shape_shape{2};
Shape image_shape_shape{2};
vector<int64_t> layer_shape{2, 2};
vector<int64_t> image_shape{10, 10};
auto LS = op::Constant::create(element::i64, layer_shape_shape, layer_shape);
auto IS = op::Constant::create(element::i64, image_shape_shape, image_shape);
auto f = make_shared<Function>(make_shared<op::PriorBoxClustered>(LS, IS, attrs), ParameterVector{});
const auto exp_shape = Shape{2, 16};
vector<float> out{0, 0, 0.15f, 0.15f, 0.34999f, 0, 0.64999f, 0.15f, 0, 0.34999f, 0.15f,
0.64999f, 0.34999f, 0.34999f, 0.64999f, 0.64999f, 0.1f, 0.2f, 0.3f, 0.4f, 0.1f, 0.2f,
0.3f, 0.4f, 0.1f, 0.2f, 0.3f, 0.4f, 0.1f, 0.2f, 0.3f, 0.4f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_expected_output<float>(exp_shape, out);
test_case.run_with_tolerance_as_fp(1.0e-5f);
}

View File

@ -1,84 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "engines_util/test_engines.hpp"
#include "engines_util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/type_prop.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, reorg_yolo_stride_2) {
// in_shape [N,C,H,W]
const auto in_shape = Shape{1, 8, 4, 4};
auto p = make_shared<op::Parameter>(element::f32, in_shape);
size_t stride = 2;
auto reorg_yolo = make_shared<op::v0::ReorgYolo>(p, Strides{stride});
auto fun = make_shared<Function>(OutputVector{reorg_yolo}, ParameterVector{p});
std::vector<float> inputs(128);
std::iota(inputs.begin(), inputs.end(), 0);
std::vector<float> expected_result{
0, 2, 4, 6, 16, 18, 20, 22, 32, 34, 36, 38, 48, 50, 52, 54, 64, 66, 68, 70, 80, 82,
84, 86, 96, 98, 100, 102, 112, 114, 116, 118, 1, 3, 5, 7, 17, 19, 21, 23, 33, 35, 37, 39,
49, 51, 53, 55, 65, 67, 69, 71, 81, 83, 85, 87, 97, 99, 101, 103, 113, 115, 117, 119, 8, 10,
12, 14, 24, 26, 28, 30, 40, 42, 44, 46, 56, 58, 60, 62, 72, 74, 76, 78, 88, 90, 92, 94,
104, 106, 108, 110, 120, 122, 124, 126, 9, 11, 13, 15, 25, 27, 29, 31, 41, 43, 45, 47, 57, 59,
61, 63, 73, 75, 77, 79, 89, 91, 93, 95, 105, 107, 109, 111, 121, 123, 125, 127};
// in_shape [N,C,H,W] -> out_shape [N, C*stride*stride, H/stride, W/stride]
Shape expected_shape =
Shape{in_shape[0], in_shape[1] * stride * stride, in_shape[2] / stride, in_shape[3] / stride};
auto test_case = test::TestCase<TestEngine>(fun);
test_case.add_input<float>(inputs);
test_case.add_expected_output<float>(expected_shape, expected_result);
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, reorg_yolo_stride_3) {
// in_shape [N,C,H,W]
const auto in_shape = Shape{1, 9, 3, 3};
auto p = make_shared<op::Parameter>(element::f32, in_shape);
size_t stride = 3;
auto reorg_yolo = make_shared<op::v0::ReorgYolo>(p, Strides{stride});
auto fun = make_shared<Function>(OutputVector{reorg_yolo}, ParameterVector{p});
std::vector<float> inputs(81);
std::iota(inputs.begin(), inputs.end(), 0);
std::vector<float> expected_result{
0, 3, 6, 27, 30, 33, 54, 57, 60, 1, 4, 7, 28, 31, 34, 55, 58, 61, 2, 5, 8, 29, 32, 35, 56, 59, 62,
9, 12, 15, 36, 39, 42, 63, 66, 69, 10, 13, 16, 37, 40, 43, 64, 67, 70, 11, 14, 17, 38, 41, 44, 65, 68, 71,
18, 21, 24, 45, 48, 51, 72, 75, 78, 19, 22, 25, 46, 49, 52, 73, 76, 79, 20, 23, 26, 47, 50, 53, 74, 77, 80};
// in_shape [N,C,H,W] -> out_shape [N, C*stride*stride, H/stride, W/stride]
Shape expected_shape =
Shape{in_shape[0], in_shape[1] * stride * stride, in_shape[2] / stride, in_shape[3] / stride};
auto test_case = test::TestCase<TestEngine>(fun);
test_case.add_input<float>(inputs);
test_case.add_expected_output<float>(expected_shape, expected_result);
test_case.run();
}